thingsToDo[] = $this->buyAFlight(); $this->thingsToDo[] = $this->takePlane(); $this->thingsToDo[] = $this->enjoyVacation(); $buyGift = $this->buyGift(); if ($buyGift !== null) { $this->thingsToDo[] = $buyGift; } $this->thingsToDo[] = $this->takePlane(); } /** * This method must be implemented, this is the key-feature of this pattern. */ abstract protected function enjoyVacation(): string; /** * This method is also part of the algorithm but it is optional. * You can override it only if you need to */ protected function buyGift(): ?string { return null; } private function buyAFlight(): string { return 'Buy a flight ticket'; } private function takePlane(): string { return 'Taking the plane'; } /** * @return string[] */ final public function getThingsToDo(): array { return $this->thingsToDo; } }