标签:www extends pac www. rri 9.png sig nbsp opened
1.基本概念
2.代码实现
package com.chengjie; interface DrawAPI { void drawCircle(int radius, int x, int y); } 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 +"]"); } } 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 +"]"); } } abstract class Shape1 { public Shape1(DrawAPI drawAPI) { this.drawAPI = drawAPI; } protected DrawAPI drawAPI; public abstract void draw(); } class Circle1 extends Shape1 { private int radius, x, y; public Circle1(DrawAPI drawAPI, int radius, int x, int y) { super(drawAPI); this.radius = radius; this.x = x; this.y = y; } @Override public void draw() { this.drawAPI.drawCircle(radius, x, y); } } public class TestBridge { public static void main(String[] args) { Circle1 redCircle = new Circle1(new RedCircle(),100, 10, 10); Circle1 greenCircle = new Circle1(new GreenCircle(),100, 10, 10); redCircle.draw(); greenCircle.draw(); } }
3.优点
4.缺点
5.应用场景
6.参考
https://www.cnblogs.com/java-my-life/archive/2012/05/07/2480938.html
http://www.runoob.com/design-pattern/bridge-pattern.html
标签:www extends pac www. rri 9.png sig nbsp opened
原文地址:https://www.cnblogs.com/forTheDream1991/p/10489798.html