Skip to content

Instantly share code, notes, and snippets.

@codejets
Last active March 20, 2016 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codejets/336fbed7e83a80e3c283 to your computer and use it in GitHub Desktop.
Save codejets/336fbed7e83a80e3c283 to your computer and use it in GitHub Desktop.
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