Java Reference
In-Depth Information
CHALLENGE 16.3
What class is the Iterator object in this code?
The point of the F ACTORY M ETHOD pattern, which the iterator() method exemplifies
well, is that clients of the method need not know which class to instantiate.
Taking Control of Which Class to Instantiate
As a client of, say, a List , you know when you need an iterator, but you don't know and
don't want to know which class to instantiate to create the iterator. In this case, the service
provider—the developers of the List class—know which class to instantiate when a client
needs an iterator. This situation, in which the service provider has more knowledge than
the client about which class to instantiate, also occurs frequently in application code.
Suppose that Oozinoz wants to start letting customers buy fireworks on credit. Early in
the design of the credit authorization system, you accept responsibility for developing
a CreditCheckOnline class that checks to see whether a customer can maintain a certain
amount of credit with Oozinoz.
As you begin development, you realize that occasionally the credit agency will be offline.
The analyst on the project determines that in this situation, the business wants you to bring up
a dialog for the call center representative and to make a credit decision based on a few
questions. To handle this, you create a CreditCheckOffline class and get it working to
specification. Initially, you design the classes as shown in Figure 16.1. The creditLimit()
method accepts a customer's identification number and returns that customer's credit limit.
Search WWH ::




Custom Search