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?
Aucun commentaire:
Enregistrer un commentaire