[英]Looking for a creational design pattern
我正在尝试找到一种可以用来简化某些对象的构造的设计模式。
基于传入的参数,自定义 class,我将从 System.Windows.Forms2CAB612F2A29FDCC0.
For instance, if the custom class has one of its members set to 'ChkBox', I want my class to return a System.Windows.Forms.CheckBox, or if the member is 'List' I want my class to return a ComboBox.
public CustomClass()
{
FieldType type;
}
和
GetControl(CustomClass type);
共同点是我想要创建的所有类都具有 Control,因为它是基础 class。 考虑到这一点,我想有一种方法可以将基础 class 上的成员设置在一个地方。
你知道我可以用来解决这个问题的任何设计模式吗?
您可以使用工厂方法模式。工厂方法模式的目的是让 class 开发人员定义用于创建 object 的接口,同时保留对要实例化哪个 class 的控制。
如需进一步帮助,您可以查看“Head first design pattern”第 4 章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.