Re: Abstract Class Theory

From: Daniel O'Connell [C# MVP] (onyxkirx_at_--NOSPAM--comcast.net)
Date: 11/01/04


Date: Mon, 1 Nov 2004 13:07:57 -0600


"Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message
news:iTshd.42920$R05.11994@attbi_s53...
>
> "Dan Sikorsky" <dsikor@gte.net> wrote in message
> news:OMWADrBwEHA.1204@TK2MSFTNGP10.phx.gbl...
>> The purpose of my posting was to determine just what the benefits are for
>> inclusion of an abstract class type in the language. We could propose
>> that
>> each class method have a default definition - if only to return true.
>> Then
>> there would be no need for abstract methods, and no abstract classes.
> Again,
>> the derived class will be overriding, or even overloading, the base class
>> anyway.
>>
>> If you don't know the definition of a method until the base class is
>> inherited by a derived class and the derived class overrides or overloads
>> it; just supply a default definition by returning true, or false.
>>
>> What specific clear benefits to having abstract methods are there?
>>
>
> If you read into the Patterns literature, you can see that the requirement
> to define an interface presents different benefits and costs than the
> option
> of defining a base class. In many patterns, the creation of code in the
> base class would defeat the pattern, or change the pattern to another,
> with
> different attributes. Sometimes, the ONLY right answer is one in which
> the
> abstract class is defined as purely abstract.
>
> In addition, if you define two abstract classes, you can have a concrete
> class inherit from both. On the other hand, you cannot have a concrete
> class inherit from two base classes due to C#'s limitation against
> multiple
> inheritance. Therefore, with the restriction against multiple
> inheritance,
> the use of abstract classes is absolutely essential to the ability of a
> developer to specify multiple interfaces for an object.
>

Actually you are confusing abstract classes and interfaces.
A C# abstract class is a literal class and only one abstract class can be
inherited from just as any other base class acts. An interface, on the other
hand, I think more closely matches waht you are tying to get at here, where
any number of interfaces may be implemented by a given class.



Relevant Pages

  • Re: Abstract Class Theory
    ... > the derived class will be overriding, or even overloading, the base class ... If you read into the Patterns literature, you can see that the requirement ... In addition, if you define two abstract classes, you can have a concrete ... class inherit from both. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Abstract Class vs. Interface
    ... A class that inherits from an abstract base class can choose ... Often interfaces represent a set of capabilities for example: ... class Apple: Fruit, Eatable ... It is unlikely that class Cow and class Apple would inherit from the same ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: interfaces
    ... abstract classes serves the purpose and have all good things then what is ... but you can implement as many interfaces as you like. ... if you are creating a "Dog" class you might inherit from ... "IChaseParkedCars" were abstract classes rather than interfaces. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Class casting.
    ... I created a base class and all pages inherit from this base class. ... Cause if they have the same signature, well that the idea of using an interface in the first place! ... Or you could implement several interfaces, but what I do not understand is how you call the different methods if they have different signatures. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: OO Design
    ... A C# class can inherit from one base class and can implement 0 to ... many interfaces. ... Tom Porterfield ...
    (microsoft.public.dotnet.languages.csharp)