美文网首页
桥接(Bridge)模式

桥接(Bridge)模式

作者: 莫库施勒 | 来源:发表于2019-08-02 19:11 被阅读0次
public interface DrawAPI {
   public void drawCircle(int radius, int x, int y);
}

public class RedCircle implements DrawAPI {
   @Override
   public void drawCircle(int radius, int x, int y) {
      System.out.println("Drawing Circle[ color: red, radius: "
         + radius +", x: " +x+", "+ y +"]");
   }
}

public class GreenCircle implements DrawAPI {
   @Override
   public void drawCircle(int radius, int x, int y) {
      System.out.println("Drawing Circle[ color: green, radius: "
         + radius +", x: " +x+", "+ y +"]");
   }
}
public abstract class Shape {
   protected DrawAPI drawAPI;
   protected Shape(DrawAPI drawAPI){
      this.drawAPI = drawAPI;
   }
   public abstract void draw();  
}

public class Circle extends Shape {
   private int x, y, radius;
 
   public Circle(int x, int y, int radius, DrawAPI drawAPI) {
      super(drawAPI);
      this.x = x;  
      this.y = y;  
      this.radius = radius;
   }
 
   public void draw() {
      drawAPI.drawCircle(radius,x,y);
   }
}

相关文章

  • 设计模式解析—桥接设计模式

    桥接模式(Bridge Pattern)定义和使用场景 定义桥接模式(Bridge Pattern):将抽象部分...

  • docker的三种网络模式

    桥接模式:bridge

  • 桥接模式

    设计模式:桥接模式(Bridge)

  • 结构型-桥接(Bridge)

    桥接(Bridge) [TOC] 定义 桥梁模式(Bridge Pattern)也叫做桥接模式,是一个比较简单的模...

  • 设计模式-桥接模式

    设计模式-桥接模式 定义 桥接模式(Bridge Pattern)也称为桥梁模式、接口(Interface)模式或...

  • 10-桥接模式

    桥接模式-Bridge Pattern【学习难度:★★★☆☆,使用频率:★★★☆☆】 处理多维度变化——桥接模式(...

  • 桥接模式

    桥接(Bridge)模式的定义如下:将抽象与实现分离,使它们可以独立变化。 桥接(Bridge)模式的优点是:由于...

  • 桥接模式-原理类图

    桥接模式(Bridge)-基本介绍 桥接模式(Bridge模式)是指:将实现与抽象放在两个不同的类层次中,使两个层...

  • 桥接模式(Bridge)

    定义它把事物对象和其具体行为、具体特征分离开来,使它们可以各自独立的变化。事物对象仅是一个抽象的概念。如“圆形”、...

  • 桥接模式-bridge

    将抽象部分与它的实现部分分离,使他们都可以独立地变化 效果及实现要点: 适用性: 在以下的情况下应当使用桥梁模式:...

网友评论

      本文标题:桥接(Bridge)模式

      本文链接:https://www.haomeiwen.com/subject/xosrdctx.html