- 1
- 0
- 约1.91万字
- 约 74页
- 2017-08-23 发布于湖北
- 举报
三、外观模式的优点 * * 使客户和子系统中的类无耦合。 外观只是提供了一个更加简洁的界面,并不影响用户直接使用子系统中的类。 子系统中任何类对其方法的内容进行修改,不影响外观的代码。 第十九章 桥接模式 * * 桥接模式(别名:柄体模式) 将抽象部分与它的实现部分分离,使得它们都可以独立地变化。 Bridge Pattern(Another Name: Handle-Body) Decouple an abstraction from its implementation so that the two can vary independently. 一 、 概述 * * 桥接模式是关于怎样将抽象部分与它的实现部分分离,使得它们都可以独立地变化的成熟模式。 二、桥接模式的结构与使用 * * 模式的结构中包括四种角色: 抽象(Abstraction) 实现者(Implementor) 细化抽象(Refined Abstraction) 具体实现者(Concrete Implementor) * * 模式的UML类图 * * 模式的结构的描述与使用 1.抽象(Abstraction): ArchitectureCose.java public abstract class ArchitectureCost{ BuildingDesign design; double unitPrice; public abstract double giveCost() ; } * * 模式的结构的描述与使用 2.实现者(Implementor) : BuildingDesign.java public interface BuildingDesign{ public double computerArea(); } * * 模式的结构的描述与使用 3.细化抽象(Refined Abstraction):BuildingCose.java public class BuildingCost extends ArchitectureCost{ BuildingCost(BuildingDesign design,double unitPrice){ this.design=design; this.unitPrice=unitPrice; } public double giveCost() { double area=puterArea(); return area*unitPrice; } } * * 模式的结构的描述与使用 4.具体实现者(Concrete Implementor):HouseDesign.java public class HouseDesign implements BuildingDesign{ double width,length; int floorNumber; HouseDesign(double width,double length,int floorNumber){ this.width=width; this.length=length; this.floorNumber=floorNumber; } public double computerArea(){ return width*length*floorNumber; } } * * 模式的结构的描述与使用 5.应用 Application.java public class Application{ public static void main(String args[]) { double width=63,height=30; int floorNumber=8; double unitPrice=6867.38; BuildingDesign design=new HouseDesign(width,height,floorNumber); System.out.println(宽+width+米,高+height+米,层数为+floorNumbe
原创力文档

文档评论(0)