0
function BankOperationChecker() {
    //This is the facade
    this.applyFor = function(facadeMethods) {
        for (var method in facadeMethods) {
            facadeMethods[method]();
        }
    }
}

function BankClient(name, amount) {
    this.name = name;
    this.amount = amount;
    this.bankOperations = new BankOperationChecker();
}

var client = new BankClient("Davi Vieira", 2000);
var checkMethods = {
    cleanBackground: function() {
        console.log('The background of this client is clean.');
    },
    canGetCredit: function() {
        if (client.amount > 1000) {
            console.log('Can get credit!');
        } else {
            console.log('Cannot get credit!');
        }
    }
}

client.bankOperations.applyFor(checkMethods);

What do you think? Facade for entrance is just one... but is that right? Is there any specific rules about creating a facade?

ketan vijayvargiya
  • 5,409
  • 1
  • 21
  • 34
  • What do you think? Have you thought anything? – Alexander McFarlane May 31 '16 at 00:27
  • 1
    Very wierd design. Whats the benefit of having BankOperationChecker aggregated inside Client here? You aren't even making use of the client instance dynamically. The BankOperationChecker also doesn't seem to actually check anything... it just executes methods in a loop. – plalx May 31 '16 at 00:32
  • Facade pattern is a pretty global design pattern since most every abstraction of code could be called a "facade". But in your case as you expose your BankOperationChecker function class I hope it would break part of the pattern. Take a look at Addy's book https://addyosmani.com/resources/essentialjsdesignpatterns/book/#facadepatternjavascript – Miguel Lattuada May 31 '16 at 00:34
  • Nope, that's nothing to do with a [facade](http://stackoverflow.com/q/5242429/1048572). – Bergi May 31 '16 at 01:45
  • Hey guys! thanks a lot for the comments. I studied a little and read what you write. So i tried again: https://gist.github.com/davivieira/5a71b73662009653ca40cebdeeeb85c8 – Davi Albuquerque Vieira Jun 01 '16 at 01:32

1 Answers1

0

No, it can't.

Facade, in English, means 'the face of a building, especially the principal front that looks onto a street or open space'. Because of this, many people confuse Facade pattern as something that acts as an entrance to something else- that, however, is not so.

As per this, the intents behind Facade patterns are:

  • Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
  • Wrap a complicated subsystem with a simpler interface.

Your example neither has bunch of subsystems nor does it have one interface to wrap all of them.

ketan vijayvargiya
  • 5,409
  • 1
  • 21
  • 34