The Simple Factory is a factory method that takes a parameter that specifies the type of object to create, and returns an object of that type. For example, in Java, you can have a ShapeFactory class that has a createShape method that takes a string as an argument, and returns a Shape object based on the string. The code could look something like this:
public class ShapeFactory {
public Shape createShape(String shapeType) {
if (shapeType == null) {
return null;
}
if (shapeType.equalsIgnoreCase("circle")) {
return new Circle();
}
if (shapeType.equalsIgnoreCase("square")) {
return new Square();
}
if (shapeType.equalsIgnoreCase("rectangle")) {
return new Rectangle();
}
return null;
}
}
The Simple Factory is easy to implement and use, but it has some drawbacks. For example, it can become too complex and hard to maintain if there are many types of objects to create, or if the creation logic involves more parameters or conditions. It also violates the open-closed principle, as you have to modify the factory method every time you add a new type of object.