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) { } }
如对本文有疑问, 点击进行留言回复!!
通过if else和switch开关语句与随机数实现模拟猜拳小游戏
网友评论