package com.leitao.demo.design;
/**
* @Description: TODO
* @Author LeiTao
* @Date 2023/4/26
* @Version V1.0
**/
public class Bridge {
public static void main(String[] args) {
Product productA = new ProductA();
Product productB = new ProductA();
Red red = new Red();
Color blue = new Blue();
productA.setName("产品A");
productB.setName("产品B");
productA.setColor(red);
productB.setColor(blue);
productA.operation();
productB.operation();
}
}
abstract class Product{
private String name;
protected Color color;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setColor(Color color){
this.color = color;
}
public abstract void operation();
}
class ProductA extends Product {
@Override
public void operation() {
color.operationImp(getName());
}
}
interface Color{
public void operationImp(String name);
}
class Red implements Color {
@Override
public void operationImp(String name) {
System.out.println(name + "的颜色是:红色");
}
}
class Blue implements Color {
@Override
public void operationImp(String name) {
System.out.println(name + "的颜色是:蓝色");
}
}