Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 794 Bytes

003_factory.md

File metadata and controls

40 lines (35 loc) · 794 Bytes

Back to the index

Factory

The Factory is the place where you create your domain services and objects. The Facade is the class that can access the Factory.

# src/Calculator/Factory.php
/**
 * @method Config getConfig()
 */
final class Factory extends AbstractFactory
{
    public function createAdder(): AdderInterface
    {
        return new Adder(
            // ...
        );
    }
}
# src/Calculator/Facade.php
/**
 * @method Factory getFactory()
 */
final class Facade extends AbstractFacade implements FacadeInterface
{
    public function sum(int ...$numbers): int
    {
        return $this->getFactory()
            ->createAdder()
            ->add(...$numbers);
    }
}

<< Facade | Config >>