Implementing a Remote Object Factory
Distributed object systems often use a design pattern called the factory pattern, which is also used in a number of Java APIs, such as XML, security, and JDBC (the JDBC DriverManager class is a factory). The idea is that instead of calling a constructor to create an object, you use a separate factory class. In the case of the Java APIs, you use the factory to hide the actual implementation. You can use different XML parser implementations—the factory chooses one. For different JDBC URLs, you might need a different JDBC driver—the DriverManager picks one.
The reason you need a factory in some Java APIs is that a constructor can't pick a different implementation class. In other words, the Driver class constructor ...
Get Special Edition Using Java™ 2 Enterprise Edition 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.