package com.eyugame.modle;
/**
* 桥接模式
* @author JYC506
*
*/
public class MyBridge extends Bridge {
@Override
void show() {
this.getSource().show();
}
public static void main(String[] args) {
Bridge bridge=new MyBridge();
bridge.setSourceable(new SourceA());
bridge.show();
bridge.setSourceable(new SourceB());
bridge.show();
}
}
abstract class Bridge {
private Sourceable source;
public void setSourceable(Sourceable source) {
this.source = source;
}
public Sourceable getSource() {
return source;
}
abstract void show();
}
interface Sourceable {
void show();
}
class SourceA implements Sourceable {
@Override
public void show() {
System.out.println("A 的方法");
}
}
class SourceB implements Sourceable {
@Override
public void show() {
System.out.println("B 的方法");
}
}
(结构型模式五)桥接模式
最新推荐文章于 2024-09-09 16:44:19 发布