我是OOP和学习设计模式的新手,所以我写了一些简单的代码来尝试一个Factory方法,除了当我想添加另一个子类型时,一切似乎都很好。这里是到目前为止的代码: public interface Person {
public String getDescription();
}
public class Adult implements Person {
@Override
我有一个域名包,它有一个叫做MyInterface的接口。我也有一个名为MyFactory的工厂类,它应该有助于在运行时创建实现MyInterface的类的实例。 领域层 interface MyInterface{
//some Domain specific methods here
}
class MyFactory{
public static MyInterfa
进行我有下面的类: public class Foo(){
int parameter;
static Set<Foo> cache=new HashSet<Foo>();
public Foo(int parameter){
this.parameter=parameter;
addToCache(this);
}
pub