abstract classes/methods

Suppose: You have a class (ANIMAL) marked as abstract with public abstract methods and public instance variables. You have the following abstract subclasses: FELINE,CANINE,extended from ANIMAL Both have inherited the abstact methods of their superclass ANIMAL.

The first concrete class in the inheritance tree must implement all abstract methods.

Now my problem: Suppose I want to create the (not abstract) class DOG which is extended from CANINE.

So I have to implement all of the abstract methods inheritated from ANIMAL and CANINE.

But since CANINE is extended from ANIMAL it has the same abstract methods. (CANINE does not get any new methods) So they are identical;except for the name.

I don't understand why I should create a class like CANINE ?

Why not simply extend a dog class simply from the ANIMAL class without a class like CANINE???

Or in general: why not create a superclass with only abstract methods (you will implement the methods later in your concrete class) and extend anything from this superclass.

like you don't need a CANINE or FELINE class and only abstract any animal from this one superclass ANIMAL

As I understand it, as that inhertiance tree stands, it doesn't make sense (although i'm sure that there will be some argument against having such a wide tree, though i can't think of any as it stands)

However, abstract classes can have non-abstract methods: behind the argument of coding to an interface and not revealing the implementation, one can argue that surly there are some methods that the implementation for certain groups of species (forgotten what then are called: genus??) will be the same; if then one specific animal does have a slight diffrent implementation for a method, it can be overloaded/overridden.

I'm sure thats one of the arguments for why this is the case; but your freindly book authour didn't have the time or felt it wasnt nessacary to flesh out those methods.

Saying all that, i'm sure other people have totally diffrent opinons... It'll be intresting to see.

Shaun

Stephan Norwood
Greenhorn

Joined: Mar 23, 2006
Posts: 14

posted Mar 23, 2006 07:15:00

0

@Shaun

thanks for your reply

the author mentioned that abstract classes can have non-abstract methods. That's why I said CANINE does not get any new method.

Shaun Williams
Greenhorn

Joined: Mar 22, 2006
Posts: 16

posted Mar 23, 2006 07:26:00

0

Stephan,

My point was that although the author chose not to write code to 'flesh out' thoose methods, some of the abstract CANINE methods could have been implemented for some behavour all canines exhibited. (Do all canines bark when they 'speak' for instance?)

Also, are the public instance varibles diffrent in the implementation of CANINE and FELINE?

The author may want to have future behavior (a method) that works only on Canines and another that works only on Felines.

public void doSomethingDoggy( Canine subject )

public void doSomethingCatty( Feline subject )

Hmm, those sound vaguely dirty. Anyhow, I'm not sure I've seen anyone make abstract classes just for that purpose and it may or may not be a Good Thing. I'm just making up explanations for something we don't understand, so it could be way off.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.