JavaScript的设计模式-代理模式

// 代理模式:使用代理对象完成用户请求,屏蔽用户对真实对象的访问
class Star {
    working() {
        console.log('明星开始工作');
    }
}                          

class Adent {
    constructor() {
        this.star = new Star();
    }

    working () {
        this.star.working();
    }
}

class Client {
    constructor () {
        this.adent = new Adent();
    }

    main () {
        this.adent.working();
    }
}

const client = new Client();
client.main()
发布了116 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/memedadexixaofeifei/article/details/103858469
今日推荐