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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access