As a OO programer,
what a ugly code! That code are totally no object-oriented, and use such
a if...else... structure to deal with different classes rather than
using polymorphic. However, uncle bob said at the follow: > Consider
what would happen if a perimeter() function were added to Geometry. The
shape classes would be unaffected! Any other classes that depended upon
the shapes would also be unaffected! On the other hand, if I add a new
shape, I must change all the functions in Geometry to deal with it.
Again, read that over. Notice that the two conditions are diametrically
opposed.
So the concept of Data Structure and Object are come out: >
Procedural code (code using data structures) makes it easy to add new
functions without changing the existing data structures. OO code, on the
other hand, makes it easy to add new classes without changing existing
functions.
Procedural code makes it hard to add new data structures because all
the functions must change. OO code makes it hard to add new functions
because all the classes must change.
But again, as a OO programer, I can't take this, I want to deal with
the scenario of change behavior more "elegantly".
Then Uncle bob jump out again and say: try Vistor pattern! (you can
find it at the footnote in page 96)