Re:When Polymorphism Fails
by thwarted on Sunday October 18, 2009 @06:31PM
(#888981)
You get the easy part: you need to decide what classes Willie is to construct the tree with. ... I won't give away the answer, but a Standard Bad Solution involves the use of a switch or case statment (or just good old-fashioned cascaded-ifs). A Slightly Better Solution involves using a table of function pointers, and the Probably Best Solution involves using polymorphism.
If the requirement was to show which classes should be used and the result is a series of conditionals or function pointers (even if they are wrapped in a single "operator" class), I'd say the requirements have not been met. To me, "classes" implies doing it with a class hierarchy or polymorphism.
If the requirement was to show which classes should be used and the result is a series of conditionals or function pointers (even if they are wrapped in a single "operator" class), I'd say the requirements have not been met. To me, "classes" implies doing it with a class hierarchy or polymorphism.