[3238] in java-interest

home help back first fref pref prev next nref lref last post

abstract methods

daemon@ATHENA.MIT.EDU (Gary Aitken)
Sat Nov 4 00:58:08 1995

Date: Fri, 3 Nov 1995 21:30:25 -0700
From: garya@village.org (Gary Aitken)
To: java-interest@java.sun.com

The java spec section 4.10.5 says that abstract methods cannot contain
a body.  Why is this restriction made?

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.

Examples which come to mind:

dump()
	Prints out (or whatever) all the relevant state for a class.
	One might well want to force this abstract to make sure any
	derived classes append their state info.

toString()
	This existing method for Object might well be implemented by
	something like
		return ( super.toString() + "My Subclass added Stuff" );

cloneAdjust( Object template )
	Force this object to resemble the template as closely as possible.
	Implements as:
		super.cloneAdjust( template );
		Make adjustments specific to this subclass here

One may well want these types of functions abstract to force conformance
to some "well-formed-object" spec which allows objects to work in some
debug environment, builder environment, etc.

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

home help back first fref pref prev next nref lref last post