Skip to content

uselessinfo/js-facade-factory

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-facade-factory

Releases:

A way to create facades that are guaranteed to have only the methods listed in their descriptions. This is a useful collaboration or organizational tool.

Sample usage:

In a shared file / module, describe the facade that will be used by multiple imlementations. The facade is described using key value pairs. The keys are the method names, and the values are the descriptions of the functionality.

var playerFacade = {
    play: 'method to play movies',
    stop: 'method to stop movies'
};

Create a facade implelemntation. Helper methods and fields may be used and will be functional, but they will not be exposed as part of the facade; they are essentially private.

var htmlPlayer = {
    time: 0,
    play: function() { ++this.time; this.helper(); return this; },
    stop: function() { console.log("html stop"); return this; },
    helper: function() { console.log("html play and play helper fired - time is now: " + this.time); },
};

Now create the facade using its description and implementation

var player = new Facade(playerFacade, htmlPlayer);

Use it:

player.play().stop();

Now you can use the same code that relies on a player for different types of players in different environments.

// Create a flash player
var player = new Facade(playerFacade, flashPlayer);

// Or create an html player
var player = new Facade(playerFacade, htmlPlayer);

// Use the player without caring which one you have.
player.play().stop();

Contributors

Changelog

0.0.1 - 2012 Nov 09 - Initial release
0.0.2 - 2013 Jan 10 - Support for properties

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%