File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Parameterized Factory Method in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "Parameterized Factory Method in Java" Watch "Parameterized Factory Method in Java" New topic
Author

Parameterized Factory Method in Java

John Zimmerman
Greenhorn

Joined: Jun 15, 2001
Posts: 2
We've been discussing whether the following technique is desirable in Java. Given a factory method which takes some identifier as input that tells it which concrete object to create and return, someone suggested that by passing the actual concrete class object instead of an identifier, the factory method would never have to be changed if new concrete classes were added to the system.
I argue that this violates encapsulation, in a way, because it forces the users of your factory to know the exact class that the factory is going to instantiate for you. What do people think?
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Any Indirection Pattern like Factory Pattern,Pure Fabrication,Singleton Pattern sort of breaks encapsulation.As Larman says this is OK in such cases (He mentions this as a desperate step).However, if you would still like to maintain encapsulation, then you can think in terms of "promoting the interface".
Hope this helps,
Sandeep


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
 
 
subject: Parameterized Factory Method in Java
 
Threads others viewed
Factory Vs Abstract Factory Pattern
Parameterized Factory Method
Abstract Factory Pattern and Factory Method Pattern
factory methods
abstract and abstract factory
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture