桥接模式(Bridge )

桥接模式是软件设计模式中最复杂的模式之一,它把事物对象和其具体行为、具体特征分离开来,使它们可以各自独立的变化。

意图:

事物对象仅是一个抽象的概念,如一个杯子,杯子形状各不相同,根据形状大小不一烧制杯子的方法也不一样。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        {

            ICup c = new Cup1();
            MakeCUP bu = new MakeCUP(1, 2, c);
            bu.Make();
            Console.Read();

        }
    }

 public   interface ICup {
        void Firing(int x, int y);
    }

   public class Cup1 : ICup {

        public void Firing(int x, int y)
        {
            Console.WriteLine("杯长{0},杯高{1}",x,y);
        }
    }

  public  class Cup2 : ICup
    {

        public void Firing(int x, int y)
        {
            Console.WriteLine("杯长{0},杯高{1}", x, y);
        }
    }




  public  interface IShape
    {
      void Make();                            
      
    }


  public class MakeCUP : IShape
  {
        private int x;
        private int y;
        private ICup cup;
        public MakeCUP(int x, int y,ICup cup)
        {
            this.x = x; this.y = y;
            this.cup = cup;
        }
        public void Make()
        {
            cup.Firing(x, y);
        }
    }



}

这篇文章可以:http://zh.wikipedia.org/wiki/%E6%A9%8B%E6%8E%A5%E6%A8%A1%E5%BC%8F

posted @ 2014-07-10 11:56  欢呼雀跃  阅读(175)  评论(0)    收藏  举报