c#中的产品交易模式
本文关键字:交易 模式 | 更新日期: 2023-09-27 18:01:34
此链接是一篇详细介绍"Product Trader Pattern"的论文
有没有人有一些经验可以分享?链接到一些示例代码?
我特别想看一些c#的实现示例。
有两个问题让我困惑:
(1)产品的创造。有人能把下面这篇论文中的示例代码翻译成c#吗
(2)规范类是否与Evans和Fowler倡导的规范模式相同?
欢呼,
Berryl
template<class ProductType, class SpecType>
class Creator
{
public:
Creator(SpecType aSpec) : _aSpecification(aSpec) {}
SpecType getSpecification() { return _aSpecification; }
ProductType * create() = 0;
private:
SpecType _aSpecification;
};
template<class ProductType, class ConcreteProductType, class SpecType>
class ConcreteCreator : public Creator<ProductType, SpecType>
{
public:
ConcreteCreator(SpecType aSpec) : Creator<ProductType, SpecType>(aSpec) {}
ProductType * create() { return new ConcreteProductType; }
}
下面是c#代码的翻译:
public abstract class Creator<ProductType, SpecType>
{
public Creator(SpecType aSpec) { _aSpecification = aSpec; }
public SpecType GetSpecification() { return _aSpecification; }
public abstract ProductType Create();
private SpecType _aSpecification;
}
public class ConcreteCreator<ProductType, ConcreteProductType, SpecType> : Creator<ProductType, SpecType> where ConcreteProductType : ProductType, new()
{
public ConcreteCreator(SpecType aSpec) : base(aSpec) { }
public override ProductType Create() { return new ConcreteProductType(); }
}