Home >Web Front-end >JS Tutorial >JavaScript Design Pattern Appearance Pattern Example_javascript skills
Appearance mode (facade mode) is a relatively simple and ubiquitous mode. The appearance pattern provides a high-level interface that makes it easier for clients or subsystems to call.
Use a simple piece of code to express it:
If you need to call the getName and getSex functions separately, you can use a higher-level interface getUserInfo to call it.
The answer is obvious. The stir-fry chef in the canteen will not stir-fry the two dishes in the same pot just because you ordered a portion of roast duck and a portion of cabbage. He would rather offer you a roast duck rice set. Also in programming, we need to ensure that functions or objects are at a reasonable granularity as much as possible. After all, not everyone likes to eat roast duck and also likes to eat cabbage.
Another benefit of the appearance mode is that it can hide the real implementation details from users, who only care about the highest-level interface. For example, in the story of the roasted duck rice set, you don't care whether the chef cooks the roasted duck first or the cabbage first, and you don't care where the duck was grown.
Finally, let’s write an example of appearance mode that we have all used: