您的位置:首页 > 其它

【设计模式】工厂方法(FactoryMethod)模式

2015-07-20 16:40 513 查看
看不见PPT的请自行解决DNS污染问题。

相关类的代码:

using FactoryPatternConsole.Model;
using FactoryPatternConsole.Service;
using System;

namespace FactoryPatternConsole
{
class Program
{
static void Main(string[] args)
{
OrderService service = new OrderService();
foreach (Order order in GetOrders())
{
service.Dispatch(order);
Console.WriteLine(string.Format("TotalCost:{0}, WeightInKG:{1}, CourierTrackingId:{2}",
order.TotalCost, order.WeightInKG, order.CourierTrackingId));
}
Console.ReadLine();
}

public static Order[] GetOrders()
{
return new Order[] {
new Order()
{
TotalCost = 100,
WeightInKG = 5,
DispatchAddress = new Address() { CountryCode = "CN" },
},
new Order()
{
TotalCost = 100.1m,
WeightInKG = 4,
DispatchAddress = new Address() { CountryCode = "CN" },
},
new Order()
{
TotalCost = 100,
WeightInKG = 5.1m,
DispatchAddress = new Address() { CountryCode = "CN" },
},
};
}
}
}


Program

执行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: