标签:sys prot his this int app on() 变化 set
桥接模式:将抽象部分与它的实现部分分离,使它们都可以独立地变化。
public abstract class PhoneApp { public abstract void funcion(); } public class PhotoPhone extends PhoneApp{ @Override public void funcion() { System.out.println("拍照手机!"); } } public class PayPhone extends PhoneApp{ @Override public void funcion() { System.out.println("买买买的手机。"); } }
public abstract class PhoneBrand { protected PhoneApp phoneApp; public void setPhoneApp(PhoneApp phoneApp) { this.phoneApp = phoneApp; } public void operation() { phoneApp.funcion(); } } public class MyPhone extends PhoneBrand{ @Override public void operation() { phoneApp.funcion(); } }
public class BridgeDemo { public static void main(String[] args) { PhoneBrand myPhone = new MyPhone(); PhoneApp photoPhone = new PhotoPhone(); myPhone.setPhoneApp(photoPhone); myPhone.operation(); PhoneApp payPhone = new PayPhone(); myPhone.setPhoneApp(payPhone); myPhone.operation(); } }
标签:sys prot his this int app on() 变化 set
原文地址:http://www.cnblogs.com/emoji1213/p/7620529.html