您的位置:首页 > 运维架构 > 网站架构

.NET架构演化--从简单需求说起

2012-12-03 09:41 225 查看
为渴求进步,所以分享我所理解的设计模式。同时也为了抛砖引玉,因为你我都需要成长!

客户需求1:请为我们电子商务网站的电子类产品计算价格,并打印显示出来.可能出现的一个实现版本代码如下:

View Code

View Code

View Code

View Code

View Code

View Code

View Code

View Code

View Code

1 public interface IGoodsFactory
2     {
3         Goods MakeMP4();
4         Goods MakePad();
5         Goods MakePhone();
6     }


View Code

1 public interface IStore
2     {
3         IEnumerator CreateGoods();
4         void Print(IEnumerator ienumerator);
5     }


View Code

public interface IStrategy
{
Double DisCounts { get; }
}


View Code

View Code

View Code

View Code

1  protected override void Init()
2         {
3             Name = "Phone";
4             Price = 4000;
5             DisCountsStrategy = new HalfPercentStrategy();
6         }


客户代码调用:

View Code

1 static void Main(string[] args)
2         {
3             IStore store = new GoodsStore(new GoodsFactory());
4             IEnumerator items = store.CreateGoods();
5             store.Print(items);
6         }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: