CD> When you are choosing different actions based on type,
CD> then you should give strong consideration to having
CD> having different types of objects to represent this
CD> rather than some sort of type field.
CD> Then CalculateBonus() becomes a virtual function that
CD> needs no maintenance when new types of employees are
CD> created withing the system.
Under many circumstances, you would only be moving your
switch(){} outside of your object.
Your use of variable type objects allows overloading of
the constructor for the parent object, which is not greatly
different from using a switch(){} construct, but hides the
actual selection process within the class creation code.
OOD, in this case, replaces the switch(){} construct
with the built-in selectivity of function overloading.
This enhances reusability and the ability to upgrade code.
So switch(){}, while not exactly evil, is, in many instances,
best left to the overloading function, rather than being
hard-coded into your functions, limiting their usefulness and
ultimately their reusability without being wholly rewritten.
In a single shot app where you just want it to work, the
switch(){} is still fine, but if you want to make solid,
OO code, then function overloading and specific data types
is a much better choice.
Is this a fairly accurate summary? :)
> ] It's never funny when you have to explain it. [ Joe Friday ]
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)
|