So I've finally started reading Designing Object-Oriented Software and my needle is stuck at a small but important point. I understand that the example I'm about to present might appear a bit out of context, because it's being developed in the book over the last few chapters, but I believe the overall idea is really simple and I'll do my best to provide context wherever I can. About me, I'm a junior developer teaching myself, so I'm hoping putting this question here will result in some fruitful discussion.
Well, finally we have the preliminaries out of the way.
The system I'm talking of an Automated Teller Machine (ATM), which we need to model in terms of object-oriented software. The discussion is about input classes that will gather numeric input from user. Two possible cases are identified - gathering account numbers, amounts, etc., and gather the PIN, which are to be rendered differently (the PIN being displayed like a password field).
So the authors defined two different classes - Form and SecureForm, the latter deriving from the former.
Now here's a section from the book (debating the utility of SecureForm) that's causing me trouble:
The intended distinction between Form and SecureForm is whether user input is echoed literally or symbolically (perhaps with an X). This can be done by invoking two different messages: getValue() and getSecureValue(), but the sender [the class making the request] would have to test to determine which message to send. This could lead to maintenance difficulties. It is better to use polymorphism; that is, to have one message that invokes different methods depending on the class of object to which it is sent. For this reason we keep SecureForm [that is, don't discard it from our design].
The part in italics doesn't make sense to me. What would the calling object have to test? Perhaps for the type of input required, but then to me it doesn't seem to make a difference whether you use polymorphism or not. Consider the following two hypothetical examples:
//inside doTransaction function of WithdrawalTransaction //example 1 form = new Form(); pin = form->getSecureValue(); //example 2 form = new SecureForm(); pin = form->getValue();
Hardly seems different to me, and not a "maintenance nightmare" by any measure.
I feel like there's some subtlety I'm missing here, but it eludes me. I'll be very grateful if someone can help me decipher the author's intent, and even better if some examples can be provided.
I hope there isn't any critical information missing from my post. If there is, please point out and I'll add more details.