不知道如何实现这样的场景:C#建筑 - 设计模式
我有一个基类让我们说
public abstract class ConfigurationBase
{
public int Id {get; set;}
public string Name {get; set;}
}
和几个派生类
public class Config1 : ConfigurationBase
{
public string Url {get;set;}
public string ReferrerUrl {get; set;}
}
public string Config2 : ConfigurationBase
{
public string Domain {get; set;}
public bool AllowCookie {get; set;}
}
和ConfigurationService
它得到用不同的参数调用。
的想法是,根据参数范围内构建配置Config1或配置Config2或实例等
所以,问题是怎么能这样用代码来实现?
根据相同的条件,实例化某种类型。
到目前为止,一种想法或者我们如何做到这一点,就是将完全限定类型存储在数据库中并通过反射进行构建。
我有点不愿意使用这种方法,我问是否还有其他答案。
为什么不去功能性编程?这是多么无聊的继承东西:) – Yavar 2012-03-07 09:53:10
对不起,但问题标题 - '架构设计模式'获得了太多的关注。只是“设计模式”会对问题的要求做更多的公正。 – 2012-03-07 10:26:28