Factory Method Design Pattern

interface ProductInterface
{
  public function getType(): string;
}

class Cog implements ProductInterface
{
  public function getType(): string
  {
    return 'Cog';
  }
}

class Widget implements ProductInterface
{
  public function getType(): string
  {
    return 'Widget';
  }
}

interface CreatorInterface
{
  public function createProduct(): ProductInterface
}

class CogCreator implements CreatorInterface
{
  public function createProduct(): ProductInterface
  {
    return new CogProduct();
  }
}

class WidgetCreator implements CreatorInterface
{
  public function createProduct(): ProductInterface
  {
    return new WidgetProduct();
  }
}
Scroll to Top