Skip to content

Instantly share code, notes, and snippets.

@codejets
Last active Mar 20, 2016
Embed
What would you like to do?
facade pattern
// Facade Pattern
/*
Facade pattern are most commonly used in combination with other patterns like module pattern.
Here we will create facade from a module.
*/
var module = (function() {
'use strict';
// Private Method
var book = {
get: function() {
// Find book with the id/index
console.log( "Getting Book Info...");
},
set: function( bID, uID ) {
// use bookID(bID) and userID(uID) to set book to user
},
download: function() {
console.log( "downloading" );
},
mailing: function(){
console.log( "Thank You for Subscribing." );
}
};
return {
// Create the facade for running whole list of process
facade: function( data ) {
book.set(data.id, data.userID);
book.get();
if ( data.download )
book.download();
if (data.mailing)
book.mailing();
}
};
}());
module.facade( {
id: 2,
userID: 123123,
download: true,
mailing: true
});
/*
$ node facade.js
Getting Book Info...
downloading
Thank You for Subscribing.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment