桥接模式

package com.life.design.bridge;

public abstract class Computer {
    protected Brand brand;

    public Computer(Brand brand) {
        this.brand = brand;
    }

    public void info(){
        brand.info();
    }
}
package com.life.design.bridge;

public class Desktop extends Computer {
    public Desktop(Brand brand) {
        super(brand);
    }

    @Override
    public void info() {
        super.info();
        System.out.println("台式机");
    }
}
package com.life.design.bridge;

public interface Brand {
    void info();
}
package com.life.design.bridge;

public class Apple implements Brand {
    @Override
    public void info() {
        System.out.print("苹果");
    }
}

 

posted on 2022-04-19 18:30  金满仓  阅读(19)  评论(0编辑  收藏  举报

导航