Re: Abstract class or interface?
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 2 May 2005 09:59:09 +0200
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
>
.
- Follow-Ups:
- Re: Abstract class or interface?
- From: Jeff Louie
- Re: Abstract class or interface?
- From: James Curran
- Re: Abstract class or interface?
- References:
- Abstract class or interface?
- From: Brett
- Abstract class or interface?
- Prev by Date: Re: Invoke Error
- Next by Date: activeX events fire again AFTER installing VS .NET 2003
- Previous by thread: Re: Abstract class or interface?
- Next by thread: Re: Abstract class or interface?
- Index(es):
Relevant Pages
|
Loading