欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js设计模式之BehavioralPatterns之Mediator

程序员文章站 2022-11-15 21:20:57
js设计模式之behavioralpatterns之mediator。 in this example we’ll greatly simplify the co...

js设计模式之behavioralpatterns之mediator。

js设计模式之BehavioralPatterns之Mediator
in this example we’ll greatly simplify the communication between the houses and
say that all messages pass through the great lord. in this case we’ll use the house of
stark as our great lord. they have a number of other houses which talk with them.

class karstark {
    constructor(greatedlord){
        this.greatlord = greatedlord;
    }
    receivemessage(message){
    }
    sendmessage(message){
        this.greatlord.routemessage(message);
    }
}

they have two functions, one of which receives messages from a third party and one
of which sends messages out to their great lord, which is set upon instantiation

class housestark{
    constructor(){
        this.karstark = new karstark(this);
        this.bolton = new bolton(this);
        this.frey = new frey(this);
        this.umber = new umber(this);
    }
    routemessage(message) {

    }
}