문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top