课程: JavaScript: Patterns

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Mediator pattern

Mediator pattern

- [Emmanuel] The mediator pattern provides a set of objects which interact with each other, mostly by having a central authority dictating the terms in between objects. It is best demonstrated with example code. Take a look at the exercise files, and pull the files from this video. You'll see here an example that is often used to demonstrate the mediator pattern. So basically what we have here is first a class called TrafficTower, so we're creating a tower, and inside of that tower we have a list of all the airplanes. And then we can actually request all the positions of the airplanes from that TrafficTower. And then we have a class called Airplane, and we're basically building a constructor with the position and trafficTower, and so on and so forth. And then we have a function that requests positions from the traffic tower. So basically the airplane can actually track itself from the traffic tower and then the…

内容