java bridge设计模式
来源:互联网 发布:中国碳纤维技术 知乎 编辑:程序博客网 时间:2024/05/22 06:32
简单的设计图:
代码的实现:
- package bridge;
- public abstractclass Clothing {
- /**
- * 抽象方法
- * @param person
- */
- public abstractvoid dressCloth(Person person);
- }
- package bridge;
- public class Jacketextends Clothing {
- @Override
- public void dressCloth(Person person) {
- // TODO Auto-generated method stub
- System.out.println(person.getType() + "穿上马甲!");
- }
- }
- package bridge;
- public class Trouserextends Clothing {
- @Override
- public void dressCloth(Person person) {
- // TODO Auto-generated method stub
- System.out.println(person.getType() + "穿上裤子!");
- }
- }
- package bridge;
- public abstractclass Person {
- private String type;
- private Clothing clothing;
- public String getType() {
- return type;
- }
- public void setType(String type) {
- this.type = type;
- }
- public Clothing getClothing() {
- return clothing;
- }
- public void setClothing(Clothing clothing) {
- this.clothing = clothing;
- }
- //抽象方法
- public abstractvoid dress();
- }
- package bridge;
- public class Manextends Person {
- public Man()
- {
- setType("男人");
- }
- @Override
- public void dress() {
- getClothing().dressCloth(this);
- }
- }
- package bridge;
- public class Womanextends Person {
- public Woman()
- {
- setType("女人");
- }
- @Override
- public void dress() {
- getClothing().dressCloth(this);
- }
- }
- package bridge;
- public class ClientTest {
- /**
- * @param args
- */
- public staticvoid main(String[] args) {
- //两类人
- Person man = new Man();
- Person lady = new Woman();
- //两种衣服的类
- Clothing jacket = new Jacket();
- Clothing trouser = new Trouser();
- jacket.dressCloth(man);
- trouser.dressCloth(man);
- jacket.dressCloth(lady);
- trouser.dressCloth(lady);
- }
- }
- java bridge设计模式
- java bridge设计模式
- JAVA设计模式-Bridge
- Java设计模式-----Bridge桥接模式
- Java设计模式-----Bridge桥接模式
- java 设计模式--桥梁模式(Bridge)
- 学习:java设计模式—Bridge模式
- Java设计模式之Bridge模式
- Java设计模式----桥接模式(Bridge)
- Java设计模式--桥梁模式【Bridge Pattern】
- java设计模式(精通系列)-Bridge模式
- 《设计模式》之Java解读--桥接Bridge
- JAVA设计模式:桥接(Bridge)
- 设计模式----Bridge模式
- 设计模式:Bridge模式
- 设计模式----Bridge模式
- 设计模式 -- Bridge模式
- 设计模式-Bridge模式
- Mysql并发控制
- 第十二周 任务三(改进版)
- B/S结构
- hdu 2546 饭卡(01背包+贪心)
- english learning websites
- java bridge设计模式
- 正在改变世界的硅谷创业趋势
- 求子集
- Android应用资源---其他资源类型(More Types)(二)
- WEB应用之:编码
- java.lang.NoClassDefFoundError jre6
- 2012不宜进入的三个技术点之:线程
- Hibernate: cannot simultaneously fetch multiple bags 问题的解决办法
- ASP.NET MVC3默认提供了11种ActionResult的实现