装饰模式-坦克大战-js

console.log('桥接模式');
//调用父类实验--------------------------------------------
class A {
    constructor() {
        this.a = 0;
    }
    exe() {
        console.log('A');
    }
}
class B extends A {
    constructor() {
        super();
    }
    exe() {
        super.exe();
        //console.log('B');
        this.append();
    }
    append() {
        console.log('B');
    }
}
//var b = new B();
//b.exe();
//坦克大战开始--------------------------------------------
// 抽象层
class Tank {
    exe() {
        
    }
}
class Decorator extends Tank {
    constructor(compoment) {
        super();
        this.compoment = compoment;
        this.appendStr = "";
    }
    exe() {
        this.compoment.exe();
        this.append();
    }
    append() {
        console.log(this.appendStr);
    }
}
class B70Tank extends Tank{
    exe() {
        console.log('sort:70');
    }
}
// 实际层
class B50Tank extends Tank {
    exe() {
        console.log('sort:50');
    }
}
class HongwaiDecorator extends Decorator {
    constructor(compoment) {
        super(compoment);
        this.compoment = compoment;
        this.appendStr = "红外扫描";
    }
}
class LiangxieDecorator extends Decorator {
    constructor(compoment) {
        super(compoment);
        this.appendStr = "水陆两栖";
    }
}
class DingweiDecorator extends Decorator {
    constructor(compoment) {
        super(compoment);
        this.appendStr = "卫星";
    }
}
// 客户端
class Client {
    main() {
        console.log("坦克装饰前------------")
        var b7 = new B70Tank();
        b7.exe();
        console.log("坦克装饰后------------")
        var hw = new HongwaiDecorator(b7);
        var lx = new LiangxieDecorator(hw);
        var dw = new DingweiDecorator(lx);
        dw.exe();
    }
}
var client = new Client();
client.main();

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值