1
JavaIntermediate#design-patterns
A creational pattern that defines a method for creating objects without exposing the exact instantiation logic to the client, letting subclasses or a factory method decide which concrete class to instantiate.
interface Shape { void draw(); }
class Circle implements Shape { public void draw() { System.out.println("Circle"); } }
class ShapeFactory {
static Shape create(String type) {
return switch (type) { case "circle" -> new Circle(); default -> null; };
}
}