//来个综合一点的吧,某生产线生产A,B 2个产品,当产品售出一件时分别通知A,B2个生产线的经理,并考虑以后还有可能会生产其他商品
//销售事件
interface ISoldNotify
{
void Notify();
}
abstract class Product:ISoldNotify
{
private IObserver obs;
public IObserver OBS
{
get { return obs; }
set { obs = value; }
}
public void Notify()
{
if (obs != null)
{
obs.GetMessage();
}
}
}
class ProductA:Product
{
}
class ProductB: Product
{
}
interface IProductFactory
{
Product CreateProduct();
}
class ProductAFactory : IProductFactory
{
public Product CreateProduct()
{
return new ProductA();
}
}
class ProductBFactory : IProductFactory
{
public Product CreateProduct()
{
return new ProductB();
observer模式的2个实现
最新推荐文章于 2020-06-02 00:02:24 发布