我是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