一、前言:
二、代码实现:
1、客户端调用
//桥接模式
btn_7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//袋子型号
BagAbstraction bag = new BigBag();
//袋子材质
Material material = new Sack();
bag.setMaterial(material);
//开始采摘
bag.pick();
}
});
2、BagAbstraction
public abstract class BagAbstraction {
protected Material material;
public void setMaterial(Material material) {
this.material = material;
}
//采摘
public abstract void pick();
}
3、BigBag
public class BigBag extends BagAbstraction{
@Override
public void pick() {
Log.d("LUO","采摘水果开始");
this.material.draw();
Log.d("LUO","采摘了一大袋");
}
}
4、Material
public interface Material {
public void draw();
}
5、Sack
public class Sack implements Material {
@Override
public void draw() {
Log.d("LUO","用麻袋");
}
}