zoukankan      html  css  js  c++  java
  • 设计模式-生成者模式之c#代码

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

    namespace BuilderModel

    {   

      public class Bike  

      {      

           private int wheels;

            public int Wheels         {             get { return wheels; }             set { wheels = value; }         }        

           private int frams;

            public int Frams         {             get { return frams; }             set { frams = value; }         }        

        }

    }

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

    namespace BuilderModel

    {    public abstract class BuilderBike   

      {        public abstract void BuilWheels(int wheeels);        public abstract void Buildframs(int frams);      

      public abstract Bike getBike();

        }

    }

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

    namespace BuilderModel

    {   

    public class ConsBike:BuilderBike

         {

           Bike bike = new Bike();

            public override Bike getBike()    

           {   

      return bike;  

        }

            public override void BuilWheels(int wheels)   

          {      

           bike.Wheels = wheels;    

          }

            public override void Buildframs(int frams)   

          {    

             bike.Frams = frams;     

        }    

    }

    }

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

    namespace BuilderModel

    {  

      public class DireBike    

    public void CreateBike(BuilderBike buildBike)    

        {       

         buildBike.Buildframs(1);      

          buildBike.BuilWheels(2);   

        }

        }

    }

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

    namespace BuilderModel

    {    

    class Program

        {      

       static void Main(string[] args)    

         {       BuilderBike buildBike = new ConsBike();

                DireBike dirBike = new DireBike();   

              dirBike.CreateBike(buildBike);       

          Bike bike= buildBike.getBike();       

          Console.WriteLine("自行车的轮自有wheels="+bike.Wheels+"个"+" "+"架子frams="+bike.Frams+"个");          

       Console.ReadKey();     

        }

        }

    }

  • 相关阅读:
    移动端性能优化动态加载JS、CSS
    右侧跟踪导航
    JQ+rotate插件实现图片旋转,兼容IE7+ CHROME等浏览器
    什么JSONP
    Web前端开发:什么是页面重回(repaints)与回流(reflow)
    javascript中的eval()函数应用以及要点
    SQL表值参数批量插入
    SQL SERVER 使用 OPENRORWSET(BULK)函数将txt文件中的数据批量插入表中(2)
    SQL SERVER 使用BULK Insert将txt文件中的数据批量插入表中(1)
    一个编程菜鸟的进阶之路(C/C++)
  • 原文地址:https://www.cnblogs.com/kexb/p/3651315.html
Copyright © 2011-2022 走看看