简体   繁体   中英

what is the difference between Decorator and mediator patterns in JavaScript

Recently I started learning the JavaScript patterns. When I am comparing Angular 4 from Angular 1.x. I have seen some new patterns in the Angular 4.

What patterns are used in the Angular 4 ?

Can we have chance to implement Decorator Pattern in the Angular 1.x?

Is Angular using $broadcasts or $emits for standard Mediator Pattern implementation?

From tutorialspoint

Mediator pattern is used to reduce communication complexity between multiple objects or classes. This pattern provides a mediator class which normally handles all the communications between different classes and supports easy maintenance of the code by loose coupling. Mediator pattern falls under behavioral pattern category. more info

Decorator pattern allows a user to add new functionality to an existing object without altering its structure. This type of design pattern comes under structural pattern as this pattern acts as a wrapper to existing class.

This pattern creates a decorator class which wraps the original class and provides additional functionality keeping class methods signature intact.

We are demonstrating the use of decorator pattern via following example in which we will decorate a shape with some color without alter shape class. more info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM