SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is the difference between abstract class and interface?

    Hello Friends,
    Tell me the difference between abstract class and interface?

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    An interface describes a contract for a class to follow, it must implement the methods verbatim described within the interface, and abstract class does not require that.

    An abstract class is an actual class (unlike an interface, which isn't a real class), it can't be instantiated, so the only way you can use an abstract class is by inheriting it. You will typically inherit it because the class you are creating is a type of the abstract class. Thus giving your new class a baseline of functionality.

  3. #3
    Non-Member
    Join Date
    Oct 2013
    Location
    Saidapet, chennai
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Abstract class is a class that contain complete and abstract both type of member and it can not be instantiated, Abstract classes are one of the essential behaviors provided by dot net. That leaves one or more method implementations unspecified by declaring one or more methods abstract.

    Interface is a type which contains only the signatures of methods, delegates or events, it has no implementation, Implementation of the methods is done by the class that which implements the interface. If there are data fields defined in an interface, then they are implicitly defined to be:
    • public.
    • static, and
    • final
    Last edited by Stevie D; Oct 16, 2013 at 10:40. Reason: Fake signature deleted

  4. #4
    Community Advisor ULTiMATE's Avatar
    Join Date
    Aug 2003
    Location
    Bristol, United Kingdom
    Posts
    2,160
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    Interfaces and abstract methods have been described across the Internet millions of times already. I doubt you'll get a better explanation on here than you will anywhere else on the web.

    That being said, if you are coming from a Java background your idea of interfaces may differ, especially when it comes to explicit interface implementation, which to my knowledge you cannot do in Java.

    If you have a complex set of business rules, it might also be worth looking at covariance, invariance, and contravariance. Again, it's been done to death elsewhere on the web, so use Google to find the explanation that works well for you, and then try building on these principles.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •