桥接模式-坦克大战-js

拟墨画扇 提交于 2019-12-02 14:33:12
console.log('桥接模式');
class AbstractAppend {
    constructor() {
        this.speed = 0;
    }
    exe() {
        console.log('speed:' + this.speed);
    }
}
class AbstractTank {
    constructor() {
        this.sort = 0;
        this.append = null;
    }
    exe() {
        console.log('sort:' + this.sort);
        if (this.append != null) {
            this.append.exe();
        }
    }
}
class B70Tank extends AbstractTank {
    constructor() {
        super();
        this.sort = 70;
    }
}
class B50Tank extends AbstractTank {
    constructor() {
        super();
        this.sort = 50;
    }
}
class Run120Append extends AbstractAppend {
    constructor() {
        super();
        this.speed = 120;
    }
}
class Run160Append extends AbstractAppend {
    constructor() {
        super();
        this.speed = 160;
    }
}

class Client {
    main() {
        var b70Tank = new B70Tank();
        b70Tank.append = new Run120Append();
        b70Tank.exe();

        var b50Tank = new B50Tank();
        b50Tank.append = new Run160Append();
        b50Tank.exe();
    }
}
var client = new Client();
client.main();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!