public class FactoryProducer {
public static AbstractFactory getFactory(String choice){
if(choice.equalsIgnoreCase("ENTITIES")){
System.out.println("entities factory created with out calling");
return new LoadEntityFactory();
}
elseif(choice.equals.IgnoreCase("UNITS"))
return new UnitFactory();
}
}
加载实体类
public class LoadEntityFactory extends AbstractFactory {
@Override
public loadEntities getLoadEntity(String entity) {
if(entity==null){
return null;
}else if (entity.equalsIgnoreCase("categories")) {
return new LoadCategoryEntity();
}
else if (entity.equalsIgnoreCase("books")) {
return new LoadBookEntity();
}
else if (entity.equalsIgnoreCase("author")) {
return new LoadAuthorEntity();
}
else if (entity.equalsIgnoreCase("publisher")) {
return new LoadPublisherEntity();
}
return null;
}
}
现在我的问题当我调用 FactoryProducer.getFactory("entities")。它会创建三个对象,当类加载到 JVM 时会创建两个对象(实体和单元),当我调用静态方法时会创建一个对象?