Created
January 4, 2011 03:15
-
-
Save fundon/764336 to your computer and use it in GitHub Desktop.
抽象工厂模式(Abstract Factory)
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
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