Re: Concrete class

From: Kutty Banerjee (kuttyb_at_wpi.edu)
Date: 05/03/04


Date: Mon, 3 May 2004 01:53:42 -0400


"mead" <philmead@light.com> wrote in message
news:n3%kc.18532$Xj6.310411@bgtnsc04-news.ops.worldnet.att.net...
> Kutty Banerjee <kuttyb@wpi.edu> wrote in message
> news:c71tg1$5av$1@bigboote.WPI.EDU...
> >
> > "mead" <philmead@light.com> wrote in message
> > news:3ATkc.8500$Ut1.255254@bgtnsc05-news.ops.worldnet.att.net...
> > > What kind of classes is qualified as "concrete classes"?
> > >
> > > When should a member function in a class defined as "pure virtual" and
> > when
> > > as "virtual"?
> > >
> > > Thanks!
> > >
> > >
> > Hi,
> > may i answer your question a little differently. its good practise
to
> > program to an interface. by interface in c++ i mean an
> > abstract class with ALL pure virtual functions.
> > So imagine you have your example of Shape and Circle. If you use
the
> > above philosophy then it means that your Shape is an interface. This is
a
> > lil different philosophy and there will be some non takers
> > for this but as a thumb rule almost never have a class with pure virtual
> > function and some non pure virtual functions. So if there is a
> > class with a pure virtual function, then let it just have such as those.
> You
> > can imagine this to be an interface.
> > The benefit of doing this is to keep the inheritance hierarchy at a
> low
> > depths!!
> >
> > kutty
> >
> I like what you said about "program to an interface." However, "The
benefit
> of doing this is to keep the inheritance hierarchy at a low depths" is
> confusing since adding an interface is always making inheritance hierarchy
> deeper. Am I right on this?
>
>
Hi,
Yes i was not clear on the part about keeping hierarchy depths low. Consider
the
following example.

Method One:
class A
    method 1
    method 2
    method 3
    //All virtual methods!!

Class B: public A
    method 1
    method 2
    method 3
    //All the above methods are different implementations than those of
    //class A.

Class C:public B
    method 1
    method 2
    method 3
    method 4
    method 5

So we have three level hierarchy here!! how to make this two level?
to begin with, class B should inherit from Class X where class X is
the interface of class A(exact same method signaturres but no body, so
abstract class)
There must be another interface Class Y with methods 4 and 5.
Class C now inherits from abstract classes X and Y ( im mixing abstract
class and interface intentionally)
and not from class B. If however Class C must have exactly the same
funcftionality for methods 1,2, 3
as those of class B then instead of inheriting from class B it could use
delegation. and if it doesnt ,
then completely forget about class B.

So finally we have class A inheriting from abstract class X and Class B
inheriting from abstract class X, Y.
If necessary it will delegate to Class B (meaning have composition of Class
B ). but in short we have two levels
of inheritance now.

kutty



Relevant Pages

  • 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: 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)
  • Re: Why I need Interface
    ... An abstract class is useful for providing some default or fundamental implementation. ... But it ties you to a specific base class, preventing you from inheriting any other base class. ... If you have no implementation you want to provide through inheritance, why lock yourself into it by using an abstract class rather than an interface? ...
    (microsoft.public.dotnet.framework)
  • Re: Confuesd about abstract class vs interface
    ... An abstract class is kind of like a new car. ... That's inheritance. ... An interface is a promise that your class will implement a set of methods ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Class Inheritance vs Interface Inheritance
    ... so then you have interface ... Pure virtual functions have implementation. ... It is an abstract class that has ... Vladimir Grigoriev ...
    (microsoft.public.vc.language)