Ken Arnold
Posts: 9
Nickname: kcrca
Registered: Mar, 2002
|
|
Re: Java Design Issues
|
Posted: Oct 17, 2002 5:29 PM
|
|
> I think Bloch is correct regarding subclassing, > though. Subclassing, especially from one concrete > class to another, frequently leads to more brittle > and less understandable code, in my opinion. > (Subclassing of abstract classes is certainly better, > because the base class is explicitly designed to be > polymorphic.)
Although I agree that subclassing is widely overused (just think -- a JButton is a Container!), I have yet to see a language that does delegation well enough to make it easy to solve the problem. Haskell has some nice features here. For example, it allows you to assert that some other type -- one you didn't write -- is (say) a Point because it fulfills the contract, possibly by some adaptor code you've written. If you do this, the thing *is* a Point, and can be used anywhere a Point is needed. This allows you to be anything you need to be without binding it into the definition of the type that everyone must share. If you need that thing to be a Point, but others don't, then it will only be a Point in your code.
It's an interesting feature. But without something like this, and probably several other features besides, working without inheritence is possible but really ugly, and so will not be done. "No rules without tools." Demanding that people reliably do painful things is not a recipe for success.
> There is a paper out there somewhere ("Inheritance > Decomposed" by Peter Frohlich) that describes pretty > nicely how subclassing can be replaced with better > techniques in every case.
Well, I wouldn't go that far, but I suppose it depends how you define "inheritence". In any case, doing this without language support would be awful. (I mean, you *can* do OO programming in C; just look at the X toolkit. But without the language support it's pretty intolerable.)
|
|