A. If this were all there were to it, you might not bother eliminating the switch. But it would already be very natural to have print() and do() methods on operations to let us eliminate the type field.
Exercise 23. Factory Method
B. You can argue it either way, but it's starting to get kind of big for an enumeration of integers.
C. What are some advantages to using dynamic class loading?
The code is simpler (no conditional logic; a single place where class is created).
The code has fewer direct dependencies (doesn't name the actual driver classes).
The delivered code can be smaller (it's no longer necessary to deliver the debugging driver class ”nothing depends on it directly).
New driver classes can be dynamically loaded without having to recompile the whole system.
D. What are some disadvantages to this new arrangement?
Performance is potentially a little worse .
A simple text scan no longer reveals all the dependencies of the code.
The configuration is a little trickier; an incorrect name or a bad CLASSPATH can leave the system unable to run.