Implementing the Mediator Design Pattern in Angular 2 By @YFain | @CloudExpo #Cloud

In any component-based framework you’ll need to implement component communications. The main principle is that components should be loosely coupled hence reusable hence testable. The mediator design pattern allows you to arrange component communications via “the man in the middle” so a component A never communicates with the component B directly. If a component needs data, someone will provide the data via bindings to the component’s input properties. Who’s this someone?Ain’t no business of the component. If a component needs to provide some data to the external world, it’ll emit events (with the data payload). Emits to whom? Ain’t no business of the component. Let whoever needs the data listen to the events from this component.

read more