mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-30 08:19:12 +02:00
PHP7 Flyweight
This commit is contained in:
@@ -16,22 +16,16 @@ class CharacterFlyweight implements FlyweightInterface
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clients supply the context-dependent information that the flyweight needs to draw itself
|
||||
* For flyweights representing characters, extrinsic state usually contains e.g. the font.
|
||||
*
|
||||
* @param string $font
|
||||
*/
|
||||
public function draw($font)
|
||||
public function render(string $font): string
|
||||
{
|
||||
print_r("Character {$this->name} printed $font \n");
|
||||
// Clients supply the context-dependent information that the flyweight needs to draw itself
|
||||
// For flyweights representing characters, extrinsic state usually contains e.g. the font.
|
||||
|
||||
return sprintf('Character %s with font %s', $this->name, $font);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user