This link是一篇详细介绍“产品交易员模式”的论文
有没有人有经验与此分享?链接到一些示例代码?
我很想看到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; }
}
答案 0 :(得分:1)
以下是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(); }
}