Re: Abstract class or interface?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



The simplest way to look at this is to understand that an interface is
functionally equivalent to a pure virtual abstract class. So an
interface is a
special case of an abstract class, one with no implementation. Given
that C#
only supports single inheritance of implementation and multiple
inheritance
of interfaces, then the question collapses to When should I use an
abstract
class with no implementation vs an interface? One answer is to use an
abstract class with no implementation when the interface is subject to
significant change. This allows you to add new methods with default
implementations to the base class without breaking existing clients of
the
base class. Another answer is to use an interface when classes may need
to
inherit from more than one interface. Another answer is to provide both
an
interface and an abstract class with default implementations of the
interface.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
.



Relevant Pages

  • Re: Pulling my hair out, I need some help
    ... base class was just that i noticed that a base class saved me more typing ... as using the interface, to the other programmers in my company i made both ... is that the plug-in must meet. ... Inheritance, it is less clear which methods and properties of the ...
    (microsoft.public.dotnet.languages.vb)
  • 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 Base Classes vs Interfaces?
    ... an abstract class is the only choice. ... You can take any class and derive from it adding in an interface ... > doesn't have to be derived from any particular base class. ... I think ICollection is a good example of the ambiguity between ...
    (microsoft.public.dotnet.languages.vb)
  • 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 ... > derived classes can only inherit one abstract class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: User Controls (Active X) - Da Process
    ... VB can't do 'real' inheritance. ... VB's 'interface inheritance' is more like interface duplication, ... Even if the class delegates to an internally held base class, ... is duplicated for every level of inheiritance. ...
    (microsoft.public.vb.general.discussion)