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 ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.