Skip to content

Instantly share code, notes, and snippets.

@fundon
Created January 4, 2011 03:15
Show Gist options
  • Save fundon/764336 to your computer and use it in GitHub Desktop.
Save fundon/764336 to your computer and use it in GitHub Desktop.
抽象工厂模式(Abstract Factory)
function AbstractFactory(){
this.createButton = function(){};
this.createBorder = function(){};
};
function Button(){};
function Border(){};
function WinFactory(){};
function MacFactory(){};
WinFactory.prototype = new AbstractFactory();
MacFactory.prototype = new MacFactory();
WinButton.prototype = new Button();
WinBorder.prototype = new Border();
MacButton.prototype = new Button();
MacBorder.prototype = new Border();
WinFactory.prototype.createButton = function(){
return new WinButton();
};
WinFactory.prototype.createButton = function(){
return new WinBorder();
};
MacFactory.prototype.createButton = function(){
return new MacButton();
};
MacFactory.prototype.createButton = function(){
return new MacBorder();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment