mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-03 12:35:04 +02:00
37 lines
732 B
PHP
37 lines
732 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\More\Delegation;
|
|
|
|
class TeamLead
|
|
{
|
|
/**
|
|
* @var JuniorDeveloper
|
|
*/
|
|
private $junior;
|
|
|
|
/**
|
|
* @param JuniorDeveloper $junior
|
|
*/
|
|
public function __construct(JuniorDeveloper $junior)
|
|
{
|
|
$this->junior = $junior;
|
|
}
|
|
|
|
public function writeCode(): string
|
|
{
|
|
return $this->junior->writeBadCode();
|
|
}
|
|
public function writeBadCode(): string
|
|
{
|
|
//note that we are passing $this from teamLead context
|
|
return $this->junior->writeReallyBadCode($this);
|
|
}
|
|
/**
|
|
* Junior can call this method
|
|
*/
|
|
public function writeReallyBadCode(): string
|
|
{
|
|
return 'Even team lead can write bad code...';
|
|
}
|
|
}
|