interface Shape {
draw(): void;
}
class Rectangle implements Shape {
public draw(): void {
console.log("Inside Rectangle::draw() method.");
}
}
class Square implements Shape {
public draw(): void {
console.log("Inside Square::draw() method.");
}
}
class Circle implements Shape {
public draw(): void {
console.log("Inside Circle::draw() method.");
}
}
class ShapeFactory {
public getShape(shapeType: string): Shape {
if (shapeType == null) return null;
if (shapeType.toLocaleUpperCase() == "CIRCLE") {
return new Circle();
} else if (shapeType.toLocaleUpperCase() == "RECTANGLE") {
return new Rectangle();
} else if (shapeType.toLocaleUpperCase() == "SQUARE") {
return new Square();
}
return null;
}
}