TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CHRIS DOWNS
from: KURT KUZBA
date: 1997-09-11 12:19:00
subject: Why the braces

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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.