知识改变人生zzz.blog.chinaunix.net
zhangzhenzhong
目前主要从事C++软件开发
全部博文(60)
2013年(3)
2012年(3)
2010年(6)
2009年(23)
2008年(25)
songlw41
garyhuc
cff23674
84378567
格伯纳
Bsolar
qq9402
胡田新
屌丝变态
nhgy200
分类:
2009-04-22 02:40:05
class MotorCycleBuilder : VehicleBuilder { override public void BuilderFrame() { vehicle = new Vehicle("摩托车"); vehicle["frame"] = "MotorCycle Frame"; } public override void BuilderDoors() { vehicle["doors"] = "0"; } public override void BuilderEngine() { vehicle["engine"] = "500 cc"; } public override void BuilderWheels() { vehicle["wheels"] = "2"; } } class ScooterBuilder : VehicleBuilder { override public void BuilderFrame() { vehicle = new Vehicle("单脚滑行车"); vehicle["frame"] = "Scooter Frame"; } public override void BuilderDoors() { vehicle["doors"] = "0"; } public override void BuilderEngine() { vehicle["engine"] = "none"; } public override void BuilderWheels() { vehicle["wheels"] = "2"; } } public class Vehicle { private string type; private Hashtable parts = new Hashtable(); public Vehicle(string type) { this.type = type; } public object this[string key] { get { return parts[key]; } set { parts[key]=value; } } public void Show() { Console.WriteLine("\n----------------------------------"); Console.WriteLine("车辆类类型:"+type); Console.WriteLine("框架:"+parts["frame"]); Console.WriteLine("发动机:"+parts["engine"]); Console.WriteLine("#轮子数:"+parts["wheels"]); Console.WriteLine("#车门数:"+parts["doors"]); } } abstract class VehicleBuilder { public Vehicle vehicle; public Vehicle Vehicle { get { return vehicle; } } abstract public void BuilderEngine(); abstract public void BuilderFrame(); abstract public void BuilderWheels(); abstract public void BuilderDoors(); } class CarBuilder : VehicleBuilder { public override void BuilderFrame() { vehicle = new Vehicle("轿车"); vehicle["frame"] = "Car Frame"; } public override void BuilderDoors() { vehicle["doors"] = "4"; } public override void BuilderEngine() { vehicle["engine"] = "2500 cc"; } public override 阅读(944) | 评论(1) | 转发(0) | 0 上一篇:C#创建者模式 下一篇:程序员面试必读 给主人留下些什么吧!~~ chinaunix网友2009-11-15 22:54:43 请问你的UML图是用什么工具画的? 回复 | 举报 评论热议 请登录后评论。 登录 注册
上一篇:C#创建者模式
下一篇:程序员面试必读
chinaunix网友2009-11-15 22:54:43
请问你的UML图是用什么工具画的?
登录 注册