Serve Lau:
> Suppose you created a class that you know has been inherited from by
> other programmers. Suppose you want to change that class. You cant
> really oversee the consequences can you? Inheritance creates another
> kind of dependency in code and there are already so many dependencies
> in structured code.
Well, the same applies to changing a procedure/function that others use...
But looks like in OOP the interrelatons may be much deeper...
> and he was so impressed with OO
> that he just had to use 3 OO constructs on every line of code.
Yeah, rather scary situation!
> And seeing there's always at least one
> of those people on the projects I work on I kinda started disliking OO
Don't you think it's abuse of OO, not use of it?
Today I've had a little talk with my friend, a JAVA programmer, and he
told
me about the state-of-the-art OO-style. Particularly, the so-called
'Command' design pattern.
Imagine you have to write a message handler. Instead of implementing a
single function with a case, and even using an array function pointers
indexed by message ids (wich is faster), the recommendation is to imlement
a generic interface (abstract object) with only one method (let's call it
execute()).
Thereafter, one has to implement a class (derived from that interface) for
_each_ of the messages! This having been done, the thing works in an
utterly awkward (to me!) way: on receipt of a message, an object of the
corresponding class (in JAVA you can refer to cl***** by their name to
dynamically choose which class to create, not sure how to do it in C++ or
Object Pascal...) is dynamically created and its execute() method called.
I asked him what all this mesh is for? If I was doing that, I'd just make
a
single handler with a case (assuming that piece is not speed-critical)...
"That improves flexibility" — he said, — "Plus adding the handling for a
new messege implies no _changes_, only _addition_ (of another class)"
Now I am wondering: is that really so im****tant to prefer adding new
functions to changing the old ones (as simple as appending another case
statement)?
Anton


|