Classes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Classes

Newsey Person
Can there be a subclass of a subclass.
Mark


Reply | Threaded
Open this post in threaded view
|

Re: Classes

Bill Schwab
Mark,

> Can there be a subclass of a subclass.

Since you ask that question, I assume that you are somewhat new to object
oriented programming.  It's also possible that you are trying to ask
something else and simply mis-typed.  I'll proceed on the newbie angle: the
short answer is yes.  A quick look at the sub-sub-...-sub-classes of Object
will show that there is effectively no limit to it.

With that said, I'll caution you that newbies often over use inheritance
because they don't see opportunties to glue together existing objects.  Some
more statically typed languages (C++ and Java comes to mind - I tend to lump
them, C#, and others together under the name C*) will force inheritance
because they will (sometimes only conditionally) prevent "touching" base
classes and/or prevent sending messages without down-casting.  Smalltalk has
many advantages in this area, and is a great place to learn design.  Get
good at Smalltalk, and you'll write better code in other languages (when you
can force yourself to go back to them).

Does that help?

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Classes

Newsey Person
I am extremely new when I look at your qualifications!

I have just embarked on a quest for knowledge and this is part of the first
assignment.
The question suggested that a subclass can have a subclass but the course
text makes no mention of this technique.
The question relates to class hierarchy.
I am using Dolphin as a benchmark of my learning progress.

Mark


"Bill Schwab" <[hidden email]> wrote in message
news:b2m918$88$[hidden email]...
> Mark,
>
> > Can there be a subclass of a subclass.
>
> Since you ask that question, I assume that you are somewhat new to object
> oriented programming.  It's also possible that you are trying to ask
> something else and simply mis-typed.  I'll proceed on the newbie angle:
the
> short answer is yes.  A quick look at the sub-sub-...-sub-classes of
Object


Reply | Threaded
Open this post in threaded view
|

Re: Classes

L. M. Rappaport
Yes, a new class can be derived from another class regardless of
whether or not "another class" is, itself, a subclass.  There are no
limits, although as Bill mentioned, the process is often abused.  

The purpose of subclassing may be specialization.  A Vehicle may be a
subclass of Object, and a PoweredVehicle may be a subclass of Vehicle.
Then you might subclass PoweredVehicle into Car and Boat, etc.  It
depends on what kind of problem you are trying to solve.  Generally,
in the most basic terms, as you proceed down from Object, you are
specializing behavior.  The trick, if you want to call it that, is
that you create your class structure based on the problem you are
trying to solve and NOT go beyond that.  

Another consideration is when to use inheritance.  For example, you
could subclass Car into WhiteCar and RedCar, but would that really
help you solve a problem?  Probably, color should be an attribute, and
not used via inheritance.

And yet another, and probably more important consideration is when to
use inheritance and when to use delegation.  For example, you could
use subclass Car into DieselCar and GasolineCar, but probably you
would have a better design if Car had an attribute called engine and
you delegated engine to an object of type GasEngine or DieselEngine.
Again, it depends upon the problem you are trying to solve.

Does that help at all?

--
Larry
[hidden email]



On Sun, 16 Feb 2003 23:10:38 -0000, "Newsey Person"
<[hidden email]> wrote (with possible editing):

>I am extremely new when I look at your qualifications!
>
>I have just embarked on a quest for knowledge and this is part of the first
>assignment.
>The question suggested that a subclass can have a subclass but the course
>text makes no mention of this technique.
>The question relates to class hierarchy.
>I am using Dolphin as a benchmark of my learning progress.
>
>Mark
>
>
>"Bill Schwab" <[hidden email]> wrote in message
>news:b2m918$88$[hidden email]...
>> Mark,
>>
>> > Can there be a subclass of a subclass.
>>
>> Since you ask that question, I assume that you are somewhat new to object
>> oriented programming.  It's also possible that you are trying to ask
>> something else and simply mis-typed.  I'll proceed on the newbie angle:
>the
>> short answer is yes.  A quick look at the sub-sub-...-sub-classes of
>Object
>
>