桥接模式

桥接(Bridge)是用于把抽象化与实现化解耦,使得二者可以独立变化。这种类型的设计模式属于结构型模式,它通过提供抽象化和实现化之间的桥接结构,来实现二者的解耦。

public class Bridge {
    public static void main(String[] args)
    {
        new CirclePaint().paint(new RedColor());
        
    }
}

interface IColor
{
    
}

interface IPaint
{
    void paint(IColor color);
}

class RedColor implements IColor
{
    RedColor()
    {
        System.out.print("红色");
    }
}

class CirclePaint implements IPaint
{
    public void paint(IColor color){
        System.out.print("画圆");
    }    
}
View Code

 

posted @ 2017-07-27 15:46  连先森  阅读(107)  评论(0编辑  收藏  举报