Re: Abstract class or interface?



Abstract classes require and imply inheritance whereas interfaces do not.

An abstract class would be used wherever it was important to enforce some
aspect of the implementation an interface is used where only the agreement
between how an object presents itself and how other objects consume it is
important.

An abstract class ensures that derived objects are part of the same
inheritance tree. Interfaces enable totally unrelated objects to present the
same face to the outside world.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Brett" <no@xxxxxxxx> wrote in message
news:eJjEzZqTFHA.2756@xxxxxxxxxxxxxxxxxxxxxxx
> I'm still trying to figure out concrete reasons to use one over the other.
> I understand the abstract class can have implementation in its methods and
> derived classes can only inherit one abstract class. The interface has
> implied abstract methods/properties and derived classes can inherit
> multiple interfaces. The interface properties/methods have no
> implementation.
>
> Besides definitions of the two, what are some conceptual reasons to use
> one over the other? Perhaps examples of this project uses an abstract
> classes vs. this one uses an interface...for these reasons.
>
> I have one project that uses an interface. I chose the interface over an
> abstract class because the derived classes all do the same thing, they
> just go about doing it in slightly different ways. Their results are
> different but conceptually what they do is the same thing. I don't ever
> see the need for adding more methods or properties to the interface. If
> there is every such a need, I can encapsulate this variability into one of
> the derived classes, since it will be "one" that has such a need rather
> than all. That make sense?
>
> Thanks,
> Brett
>


.



Relevant Pages

  • Re: Concrete class
    ... >> abstract class with ALL pure virtual functions. ... >> above philosophy then it means that your Shape is an interface. ... > of doing this is to keep the inheritance hierarchy at a low depths" is ...
    (comp.lang.cpp)
  • Re: Abstract class or interface?
    ... > I'm still trying to figure out concrete reasons to use one over the other. ... > in its methods and derived classes can only inherit one abstract class. ... The interface properties/methods have no implementation. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Abstract class or interface?
    ... >>derived classes can only inherit one abstract class. ... The interface properties/methods have no implementation. ... > and rotate "things" along all three X, Y, and Z coordinate axis. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Declaring a Constructor in an Interface?
    ... i have read many places that an interface is faster than ... but would You also claim that an abstract class ... Dennis JD Myrén ... > Virtual methods always means performance overhead. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A Java "interface" declaration does not allow a constructor to be specified in it ...
    ... > If Java supported full multiple inheritance (which is ... > the implication of interface constructors), ... abstract class MailDelivery has a non-abstract method "transport", ...
    (comp.lang.java.programmer)

Loading