Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 855 Bytes

002_facade.md

File metadata and controls

41 lines (33 loc) · 855 Bytes

Back to the index

Facade

The Facade is the entry point of your module. See an example:

# src/Calculator/FacadeInterface.php
interface FacadeInterface 
{
    public function sum(): void;
}
# src/Calculator/Facade.php
/**
 * @method Factory getFactory()
 */
final class Facade extends AbstractFacade implements FacadeInterface
{
    public function sum(int ...$numbers): int
    {
        $this->getFactory()
            ->createAdder()
            ->add(...$numbers);
    }
}

A Facade is a "ready to use" thing:

$facade = new Facade();
$result = $facade->sum(2, 3);  

The Facade uses the Factory to create the module's domain instances and executes the desired behaviour from them. Nothing less, nothing more.

<< Basic Concepts | Factory >>