Last active
March 20, 2016 08:53
-
-
Save codejets/336fbed7e83a80e3c283 to your computer and use it in GitHub Desktop.
facade pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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