Re: Warning
Michael Doubez wrote:
I hear what you say but I have a gut feeling that the is-a/has-a
system is very good for tuition of concept thinking but rarely scale
in practice.
I wouldn't say "rarely". It may be true that *bad design* often
results in programs where the "is-a" school of design just doesn't work,
and that there are tons of examples of such bad design out there.
However, that doesn't mean that the "is-a" concept is flawed in itself.
It just has to be properly implemented.
Besides the "widget"-style design that is extremely common in GUI
frameworks, another good example of "is-a" polymorphism is the C++
streams: A function may take a reference to eg. a std::ostream, and you
can give it std::cout, an std::ofstream or an std::ostringstream, and it
will work nicely. This is object-oriented design in action.
There may be situations where this design doesn't work but, after all,
OOD is not a silver bullet.
I have in mind a badly designed GUI library (fltk IIRC) where
everything had been put into the /Widget/ base class (the actions
callback, the label ...) and subclasses used them or not depending on
the specialization.
This is usually where multiple inheritance (even if in a limited form)
steps in to aid in a better overall design. For example a button may be
both a widget and a mouse event listener. Hence a button can be given to
any code expecting a widget, or one expecting a mouse event listener
because the button is both.
(For some unfathomable reason many programmers, even experienced ones,
have this misconception that multiple inheritance is a bad thing, and
will go to great lengths to argue how you don't need it, how they don't
use it, and how "interfaces" and "protocols" aren't *really* multiple
inheritance (even though they are). I don't understand this attitude.
Multiple inheritance is a very nice way of simplifying your design and
making it more logical and modular.)
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---