PHP7 Flyweight

This commit is contained in:
Dominik Liebler
2016-09-23 10:34:53 +02:00
parent de196765cf
commit 2e287acdf7
7 changed files with 343 additions and 336 deletions

View File

@@ -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);
}
}