Home > Web Front-end > JS Tutorial > JavaScript Design Pattern Series 8: Appearance Pattern

JavaScript Design Pattern Series 8: Appearance Pattern

不言
Release: 2018-04-02 14:23:56
Original
1042 people have browsed it

This article shares with you the eighth series of JavaScript design patterns: Appearance mode. Friends who are interested can take a look.

Appearance mode

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
}
Copy after login
// 通过同一接口调用子系统

import app from './app'

app.A.getA(params);
app.B.getB(params);
Copy after login

The difference with the adapter pattern

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template