Answer the question
In order to leave comments, you need to log in
What is the essence of the Facade pattern?
I read a little about the Facade pattern, and I want to figure out if I understood it correctly, like when there are some operations, for example, on an object, and these operations need to be performed in many places in the application, but they may differ slightly, then Facade would be useful here? Is it like a wrapper over operations to perform them in one line and not duplicate code, and using parameters to use differently in each situation? that is, here I wrote an example in js
a = new ExampleObjeact();
a.makeSome1();
a.makeSome2();
a.makeSome3();
a = new ExampleObjeact();
makeSomething(a, makeLastSome) {
a.makeSome1();
a.makeSome2();
if (makeLastSome) {
a.makeSome3();
}
}
makeSomething(a, true);
Answer the question
In order to leave comments, you need to log in
No, not right.
For your example, the correct one would be:
a = new ExampleObjeact();
a.makeSomething = function(action) {
return a[action]();
});
a.makeSomething('makeSome1');
a.makeSomething('makeSome2');
a.makeSomething('makeSome3');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question