This article shares with you the eighth series of JavaScript design patterns: Appearance mode. Friends who are interested can take a look.
Appearance mode refers to providing a unified interface To access multiple different interfaces of multiple subsystems and provide a unified high-level interface for a set of interfaces in the subsystem. It makes the subsystem easier to use, not only simplifying the interface in the class, but also decoupling the caller and the interface.
Appearance mode is very common in our daily work.
Let’s look at an example:
// a.js export default { getA (params) { // do something... } } // b.js export default { getB (params) { // do something... } } // app.js 外观模式为子系统提供同一的高层接口 import A from './a' import B from './b' export default { A, B }
// 通过同一接口调用子系统 import app from './app' app.A.getA(params); app.B.getB(params);
The adapter pattern wraps an object to change its interface, while the appearance pattern wraps a group of objects Wrapped to simplify its interface.
The adapter converts the interface into different interfaces, while the appearance mode provides a unified interface to simplify the interface.
Related recommendations:
JavaScript Design Pattern Series Three: Builder Pattern
##JavaScript Design Pattern Series Five: Adapter Pattern
The above is the detailed content of JavaScript Design Pattern Series 8: Appearance Pattern. For more information, please follow other related articles on the PHP Chinese website!