结构型模式:Bridge(桥接)
来源:互联网 发布:网络歌曲我想静静 编辑:程序博客网 时间:2024/06/05 09:19
http://zh.wikipedia.org/wiki/%E6%A9%8B%E6%8E%A5%E6%A8%A1%E5%BC%8F
/** "Implementor" */interface DrawingAPI{ public void drawCircle(double x, double y, double radius);} /** "ConcreteImplementor" 1/2 */class DrawingAPI1 implements DrawingAPI{ public void drawCircle(double x, double y, double radius) { System.out.printf("API1.circle at %f:%f radius %f\n", x, y, radius); }} /** "ConcreteImplementor" 2/2 */class DrawingAPI2 implements DrawingAPI{ public void drawCircle(double x, double y, double radius) { System.out.printf("API2.circle at %f:%f radius %f\n", x, y, radius); }} /** "Abstraction" */interface Shape{ public void draw(); // low-level public void resizeByPercentage(double pct); // high-level} /** "Refined Abstraction" */class CircleShape implements Shape{ private double x, y, radius; private DrawingAPI drawingAPI; public CircleShape(double x, double y, double radius, DrawingAPI drawingAPI) { this.x = x; this.y = y; this.radius = radius; this.drawingAPI = drawingAPI; } // low-level i.e. Implementation specific public void draw() { drawingAPI.drawCircle(x, y, radius); } // high-level i.e. Abstraction specific public void resizeByPercentage(double pct) { radius *= pct; }} /** "Client" */class BridgePattern { public static void main(String[] args) { Shape[] shapes = new Shape[2]; shapes[0] = new CircleShape(1, 2, 3, new DrawingAPI1()); shapes[1] = new CircleShape(5, 7, 11, new DrawingAPI2()); for (Shape shape : shapes) { shape.resizeByPercentage(2.5); shape.draw(); } }}
- Bridge 桥接(结构型模式)
- 结构型模式:Bridge(桥接)
- Bridge桥接(结构型模式)
- 【结构型模式】bridge(桥接)
- 结构型模式-桥接(bridge)
- 2.2 Bridge(桥接) -- 对象结构型模式
- [设计模式-结构型]桥接(Bridge )
- 设计模式-结构型-bridge桥接
- 9.Bridge(结构型模式)
- 结构型-桥接模式(Bridge)
- bridge模式-结构型模式
- 设计模式之结构型模式(一)-----桥接(bridge)模式
- 设计模式笔记--结构型模式之二--桥接 Bridge
- 桥接(bridge) 模式--结构型模式之五
- 【设计模式基础】结构型模式 - 4 - 桥接(Bridge)
- 设计模式之类对象结构型 — BRIDGE (桥接)模式
- 设计模式(十二)桥模式(Bridge)-结构型
- 桥接模式(Bridge)(对象结构型模式)
- Android开发性能优化简介
- 关于数据挖掘推荐系统实现
- jsp response对象
- error: 'glGenFramebuffersOES' was not declared in this scope
- 关注firefox os
- 结构型模式:Bridge(桥接)
- java Class.forName 介绍
- Cannot find module with tag 'libjpeg' in import path
- Cocos2dx新建项目在eclipse中无法编译运行
- HTTP报文解析器
- asterisk read无法接受按键
- ffmpeg教程
- Tomcat部署web项目
- Java WEB开发中路径问题的总结