我觉得我应该开始在我的一些代码上使用工厂方法设计模式。这就是我正在做的事情;
下面的代码是我的 Accom 命名空间的生成器类:
namespace Accom {
public class Generator {
int? _id;
string _name;
public Generator(int? id = null, string name = null) {
_id = id;
_name = name;
}
public string GetBaseUrl() {
//some logic sits here.
return somestring;
}
//Can have some other methods as well
}
}
我也会对 Traf 命名空间进行相同的启动:
namespace Traf {
public class Generator {
int? _id;
string _name;
public Generator(int? id = null, string name = null) {
_id = id;
_name = name;
}
public string GetBaseUrl() {
//some logic sits here. Same one with the Accom.
return somestring;
}
//Can have some other methods as well
}
}
因此,这将一次又一次地重复。
我试图为此创建一些工厂模式,但是所有的抽象类都是混合的,我很困惑(我认为这是因为这是我第一次尝试做类似的事情)。
任何人都可以在这方面帮助我并指出我可以阅读并从中理解的好的源代码吗?