Question

I'm trying to create some variation of the abstract factory pattern.
The Factory is supposed to allow a plugin-like insertion of new implementation of concrete factories.

e.g.

public class AbstractFactory  
{  
  //some code here  
  public static void addNewImpl(String implName, /*class path or something else*/)  
  {  
    //dynamic class validity check  
    //save class somehow (db I guess)  
  }  

  public static getImpl(String name)
  {
    //is impl available  
    //return if valid  
  }  
}  

I'm not sure I'm tackling the problem correctly or if I should reconsider my design.

Was it helpful?

Solution

I would go ahead like this:

  • get your code to compile :-)
  • You need to define a factory interface which builds your target objects
  • As your classes are typically loaded at application startup, it should be sufficient, that your DelegateFactory (you called it AbstractFactory) reads a properties file from the classpath at startup.
  • For each entry in the properties file use the key as lokup and the class name as value of the entry.
  • Sit back
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top