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