On Apr 9, 2008, at 13:51, David Cantrell wrote:
On Tue, Apr 08, 2008 at 09:36:21PM +0200, Marco Von Ballmoos wrote:
Consider this:
a GothMusic is-a ModernMusic is-a Music
Music defines a few methods, including getmood() which throws an
exception if you haven't already setmood(). ModernMusic defines a few
extra methods to do with electrickery and amplification, but inherits
Music's getmood() and setmood() unchanged.
GothMusic inherits from ModernMusic (it needs all the electrickery and
amplification) and also supplies its own version of getmood (which
always returns "suicidal") and setmood (which throws an exception
unless
you tell it to be suicidal).
GothMusic and ModernMusic are not interchangeable.
Good point. Tough to prevent, though. Design-by-Contract provides
restrictions on how pre- and postconditions can be added in derived
methods, but you can still just throw an exception anywhere. Java has
its checked exceptions, but it can cause be a lot of work maintaining
all of the declared exceptions -- and a RuntimeException can be
thrown at any time.
--
Marco Von Ballmoos
http://earthli.com - Home of the earthli WebCore; PHP web sites made
simple.