Class Creator

java.lang.Object
Creational.FactoryMethod.Creator
Direct Known Subclasses:
ConcreteCreatorA, ConcreteCreatorB

public abstract class Creator extends Object
Abstract Creator class in the Factory Method design pattern. The Creator class declares the factory method `createProduct`, which must be implemented by concrete subclasses to create specific types of products. It also provides a common operation `someOperation` that utilizes the product created by the factory method.
  • Constructor Details

    • Creator

      public Creator()
      Default constructor for Creator.
  • Method Details

    • createProduct

      public abstract Product createProduct()
      Factory method to create a product. This method is abstract and must be overridden by subclasses to specify the type of product to be created. The factory method promotes flexibility by delegating the creation logic to concrete creators.
      Returns:
      A product created by the factory method.
    • someOperation

      public void someOperation()
      A common operation that demonstrates the use of the product. This method creates a product using the factory method and performs an operation on it. This demonstrates the separation of product creation (handled by `createProduct`) from the logic that uses the product (handled here).