Harry lives a miserable life.
Harry receives an invitation to another world.
Family prevents Harry from accepting the invitation.
Harry meets a mentor.
Harry travels to a new world.
Harry makes friends and faces rivals.
Harry ventures into a dangerous and forbidden place.
Harry is confronted with a life-or-death challenge.
Harry receives a reward.
Harry returns to a place of safety.
Harry is transformed by his experiences.
Harry returns to his normal life,
strengthened by new confidence.
Luke lives a miserable life.
Luke receives an invitation to another world.
Family prevents Luke from accepting the invitation.
Luke meets a mentor.
Luke travels to a new world.
Luke makes friends and faces rivals.
Luke ventures into a dangerous and forbidden place.
Luke is confronted with a life-or-death challenge.
Luke receives a reward.
Luke returns to a place of safety.
Luke is transformed by his experiences.
Luke returns to his normal life,
strengthened by new confidence.
Lord of the Rings
The Matrix
Men in Black
Batman Begins
The Lion King
Aladdin
The Wizard of Oz
"Monomyth"
-- James Joyce, 1939
"Hero's Journey" / "Quest"
-- Joseph Campbell: "The Hero with a Thousand Faces", 1949
"Here, fully explored,
was the pattern I had been sensing.
Campbell had broken the secret
code of story."
-- Christopher Vogler: "The Writer's Journey: Mythic Structure for Writers", 1992
At the core […] is the idea people should design their homes, streets, and communities.
This idea […] comes from the observation most of the wonderful places of the world were
not made by architects, but by the people.
-- Christopher Alexander et al., "A Pattern Language"
Life Cycle
Market of Many Shops
Street Cafe
Master and Apprentice
"Singletons are the path to the dark side."
-- Stefan Priebsch
public static function getInstance(): self
{
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
...
$singleton = Singleton::getInstance();
...
"Singletons are the path to the dark side."
-- Stefan Priebsch
interface Something
{
public function doWork(): void;
...
}
final readonly class SomethingImplementation
implements Something
{
public function doWork(): void
{
// ...
}
}
final readonly class ProtectingProxy implements Something
{
public function __construct(
private readonly Something $something
) {}
public function doWork(): void
{
if (!access_is_allowed) {
throw new Exception('No nice things for you.');
}
$this->something->doWork();
}
}
final readonly class LazyLoadingProxy implements Something
{
private Something $something;
public function __construct(
private SomethingId $id,
private SomethingRepository $repository
) {}
...
...
public function doWork(): void
{
if (!isset($this->something)) {
$this->something =
$this->repository->findById($this->id);
}
$this->something->doWork();
}
}
final readonly class RevenueReport
{
public function __construct(
private RevenueRecognitionStrategy $strategy
) {}
...
}
final readonly class RevenueReport
{
...
private function calculateRevenue(
Employee $employee,
Period $period
): void
{
return $this->strategy->calculateRevenue(
$employee,
$period
);
}
}
abstract readonly class Application
{
final public function run(): void
{
$request = HttpRequest::fromSuperGlobals();
$response = $this->handleRequest($request);
$response->send();
}
abstract protected function
handleRequest(HttpRequest $request): HttpResponse;
}
Transaction Script
Domain Model
Service Layer
Active Record
Data Mapper
Repository
Data Transfer Object
Server Session State
Template View
Front Controller
introduce Design Patterns into your application
introduce Design Patterns into your team
learn more about Design Patterns
Talk to me about Design Patterns, Software Architecture, and PHP in general: