Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Interface and abstract class why we use

Interface and abstract class why we use

Scheduled Pinned Locked Moved C#
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahulmaurya123
    wrote on last edited by
    #1

    Interface and abstract class why we use please explain

    P J L J 4 Replies Last reply
    0
    • R rahulmaurya123

      Interface and abstract class why we use please explain

      P Offline
      P Offline
      Peter Leow
      wrote on last edited by
      #2

      An excellent article from codeproject: Abstract Class versus Interface[^]

      1 Reply Last reply
      0
      • R rahulmaurya123

        Interface and abstract class why we use please explain

        J Offline
        J Offline
        Jason Gleim
        wrote on last edited by
        #3

        Because it is a smart thing to do. ;) Both allow you to stub out or define aspects of a class that you may know but not completely or you may not be the one ultimately filling in the functionality. Interfaces allow you to specify what properties, methods, and events MUST be present on an object that conforms to that interface. Take, for example, INotityPropertyChanged. If an object implements that interface, then it MUST expose a PropertyChanged event with a specific signature. When another object wants to be notified that a property changed, it can inspect the target class to see if that interface is implemented and if so, hook the event. Because now you know what the event name and signature must be. Interfaces, however, only specify the properties, events, and methods that a class must expose and a class may implement more than one interface. Abstract classes, however, have a bit more meat on their bones. They are actual classes but simply stub the method functionality leaving it to be implemented in a class that inherits from the abstract class. A good example might be a data access object that exposes some data stored in the database. You would define an interface for the class including the methods needed to get and save data. You might then create an abstract class that provides some basics but doesn't include any details on how to get to the database. Finally, you might create two or three concrete classes from the abstract class that each know how to connect to a specific database server... maybe one for SQL, another for Oracle, and a 3rd for NoSQL. At runtime you can use reflection to find the proper concrete class and load it. Your code works with only the interfaces but at runtime is provided with the concrete instance of the appropriate class. HTH! Jason

        1 Reply Last reply
        0
        • R rahulmaurya123

          Interface and abstract class why we use please explain

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          No.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • R rahulmaurya123

            Interface and abstract class why we use please explain

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            rahulmaurya123 wrote:

            please explain

            ...how to use google... https://support.google.com/websearch/answer/134479?hl=en[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups