The following is an excerpt taken from OOSC2 based around Bertrand Meyers
Single Choice principle :
"The case instruction of Pascal and Ada comes in handy here; it is of course on purpose that its syntax mirrors the form of the declaration of a record type with variants. Fortran and C will emulate the effect through multi-target goto instructions (switch in C). In these and other languages a multi-branch conditional instruction (if - then - elseif - elseif - else - end) will also do the job."
"Aside from syntactic variants, the principal observation is that to perform such a discrimination every client must know the exact list of variants of the notion of publication supported by A. The consequence is easy to foresee. Sooner or later, you will realize the need for a new variant, such as technical reports of companies and universities. Then you will have to extend the definition of type PUBLICATION in module A to support the new case. Fair enough: you have modified the conceptual notion of publication, so
you should update the corresponding type declaration. This change is logical and inevitable. Far harder to justify, however, is the other consequence: any client of A, such as B, will also require updating if it used a structure such as the above, relying on an explicit list of cases for p. This may, as we have seen, be the case for most clients."
Originally posted by Ilja Preuss :
but in my opinion replacing switch/if statements by polymorphism doesn't buy you anything *in general*
Did you mean that ,with polymorphism, there's still some adding of new types to do ?
But no updating of any additional clients is required ?
Which means Answer D is more correct.
regards
[ October 16, 2003: Message edited by: HS Thomas ]