[3334] in java-interest
re:abstract methods
daemon@ATHENA.MIT.EDU (Gary Aitken)
Tue Nov 7 23:37:14 1995
Date: Tue, 7 Nov 1995 18:55:56 -0700
From: garya@village.org (Gary Aitken)
To: "andrew (a.) francis" <andrewfr@bnr.ca>, java-interest@java.sun.com
In-Reply-To: <"25130 Mon Nov 6 07:02:40 1995"@bnr.ca>
>> The java spec section 4.10.5 says that abstract methods cannot contain
>> a body. Why is this restriction made?
>
>If the all the methods of abstract classes had method bodies, I don't
>understand why one would want abstract classes in the first place?
>(note: I believe the new Java language spec needs the keyword "abstract"
>to make a method abstract)
I'm not suggesting that all abstract methods have bodies; only that they
should be *allowed* to have bodies, as they are in C++.
>> There are plenty of situations where it makes sense to have an abstract
>> method which also supplies a default body. In particular, for methods
>> where the behavior is to call the superclass' method, then append semantics
>> for the subclass.
>
> Couldn't the same effect be achieved by having a normal base class and
>have sub-classes override the methods it is interested in changing, and in
>the process, make calls to the overridden superclass method via the
>super variable? Or if you do not want the pseudo-abstract class instantiated,
>couldn't you make its constructors protected?
Yes, but you lose the reason the abstract method exists -- forcing the
derived class to override the method. The whole purpose of the abstract
method is to force the implementor of a derived class to implement the
method. If you don't make it abstract, one can derive and forget to
do the override, causing incorrect behavior.
Gary Aitken garya@village.org
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com