标签:需要 笔记 问题 bridge abstract http 失败 抽象 苹果
package com.mjh.bridge;
public interface Brand {
public void info();
}
//联想品牌
class Lenovo implements Brand {
@Override
public void info() {
System.out.print("联想");
}
}
//苹果品牌
class Apple implements Brand{
@Override
public void info() {
System.out.print("苹果");
}
}
package com.mjh.bridge;
public abstract class Computer {
//组合 桥(连接点)
protected Brand brand;
public Computer(Brand brand) {
this.brand = brand;
}
public void info(){
brand.info();//自带品牌
}
}
class DeskTop extends Computer{
public DeskTop(Brand brand) {
super(brand);
}
@Override
public void info() {
super.info();
System.out.println("台式机");
}
}
class LapTop extends Computer {
public LapTop(Brand brand) {
super(brand);
}
@Override
public void info() {
super.info();
System.out.println("笔记本");
}
}
package com.mjh.bridge;
public class Test {
public static void main(String[] args) {
//苹果笔记本
Computer computer = new LapTop(new Apple());
computer.info();
//联想台式机
Computer computer1=new DeskTop(new Lenovo());
computer1.info();
}
}
标签:需要 笔记 问题 bridge abstract http 失败 抽象 苹果
原文地址:https://www.cnblogs.com/mjjh/p/13324429.html