Appearance mode (facade mode) is a relatively simple and ubiquitous mode. Appearance mode provides a high-level interface, which makes it easier to call clients or subsystems.
Use a simple piece of code to express:
The code copy is as follows:
var getName = function(){
return ”svenzeng”
}
var getSex = function(){
return 'man'
}
If you need to call the getName and getSex functions respectively, you can use a higher-level interface getUserInfo to call it.
The code copy is as follows:
var getUserInfo = function(){
var info = a() + b();
return info;
}
The answer is obvious. The canteen's cooking chefs will not stir-fry these two dishes in the same pot just because you booked a roast duck and a cabbage. He would rather provide you with a set meal of roast duck rice. Also in programming, we need to ensure that the 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 advantage of appearance mode is that it can hide real implementation details from users, and users only care about the highest level interface. For example, in the story of the roast duck rice set meal, you don’t care whether the master makes roast duck first or stir-fry cabbage first, and you don’t care where the duck grew up.
Finally, let’s write an example of the appearance pattern that we have all used:
The code copy is as follows:
var stopEvent = function( e ){ //Block events at the same time default behavior and bubble
e.stopPropagation();
e.preventDefault();
}