is it possible to make superclass extend another class ?

K

krislioe

Hi all,

I have Class A as superclass.

I have Class B extend Class A
Then Class C extend Class B

Is it possible to make Class A Extend Class D ?

Thank you,
xtanto
 
A

Andrew Thompson

I have Class A as superclass.

I have Class B extend Class A
Then Class C extend Class B

Is it possible to make Class A Extend Class D ?

Sure. So long as D extends none of A, B or C.

BTW - are you sure this is the best design?
A lot of layers of 'extends' sometimes suggests 'no'.
(and those are silly class names - even for an abstraction)

Andrew T.
 
P

paul_himanshu

Andrew said:
Sure. So long as D extends none of A, B or C.

BTW - are you sure this is the best design?
A lot of layers of 'extends' sometimes suggests 'no'.
(and those are silly class names - even for an abstraction)

Andrew T.
 
P

Patricia Shanahan

Andrew said:
Sure. So long as D extends none of A, B or C.

BTW - are you sure this is the best design?
A lot of layers of 'extends' sometimes suggests 'no'.
(and those are silly class names - even for an abstraction)

Andrew T.


A couple of additional restrictions:

A must be a class you can change.

A's immediate superclass must also be a superclass of D, trivially true
if A is a direct subclass of Object.

I share Andrew's doubts about a design with that many layers.

Patricia
 
K

krislioe

Hi,
Thank you for your response.
I share Andrew's doubts about a design with that many layers.

As a rule of thumb, how many is indicating too many ?

Thank you,
xtanto
 
P

Patricia Shanahan

> Hi,
> Thank you for your response.
>
>
> As a rule of thumb, how many is indicating too many ?
>

I don't think there is any rule of thumb, but an increasing queasiness
as the number of inheritance levels increases. We have at least 5 levels
here (Object, D, A, B, C). Whether it makes sense to go that deep
depends on what the classes are about, but it is deep enough that I
would question it in my own code.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top