Re: Concrete class
From: Kutty Banerjee (kuttyb_at_wpi.edu)
Date: 05/03/04
- Next message: E. Robert Tisdale: "Re: passing an argument by reference"
- Previous message: Bob: "Re: [OT] Microsoft C/C++ Optimizing Compiler Version 7.00"
- In reply to: mead: "Re: Concrete class"
- Next in thread: DaKoadMunky: "Re: Concrete class"
- Reply: DaKoadMunky: "Re: Concrete class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: E. Robert Tisdale: "Re: passing an argument by reference"
- Previous message: Bob: "Re: [OT] Microsoft C/C++ Optimizing Compiler Version 7.00"
- In reply to: mead: "Re: Concrete class"
- Next in thread: DaKoadMunky: "Re: Concrete class"
- Reply: DaKoadMunky: "Re: Concrete class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|