Skip to content

Instantly share code, notes, and snippets.

@mplacona
Created April 20, 2014 10:57
Show Gist options
  • Save mplacona/11111173 to your computer and use it in GitHub Desktop.
Save mplacona/11111173 to your computer and use it in GitHub Desktop.
class ShapeFactory{
IShape getShape(String shapeType){
// check for nulls being passed
if(shapeType == null){
return null;
}
// check for types
var type = shapeType.toLowerCase();
switch(type){
case "rectangle":
return new Rectangle();
break;
case "circle":
return new Circle();
break;
case "square":
return new Square();
break;
}
// we always return null if there are no matches
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment