Chinaunix首页 | 论坛 | 博客
  • 博客访问: 501057
  • 博文数量: 60
  • 博客积分: 2673
  • 博客等级: 少校
  • 技术积分: 700
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-09 00:25
个人简介

目前主要从事C++软件开发

文章分类

全部博文(60)

文章存档

2013年(3)

2012年(3)

2010年(6)

2009年(23)

2008年(25)

我的朋友

分类:

2009-04-22 02:40:05

c#实例------车间造车程序;
UML图:

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图是用什么工具画的?