mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 20:20:15 +02:00
fixed eol and typecast
This commit is contained in:
@@ -6,8 +6,8 @@ namespace DesignPatterns\Structural\Flyweight;
|
||||
* Implements the flyweight interface and adds storage for intrinsic state, if any.
|
||||
* Instances of concrete flyweights are shared by means of a factory.
|
||||
*/
|
||||
class CharacterFlyweight implements FlyweightInterface {
|
||||
|
||||
class CharacterFlyweight implements FlyweightInterface
|
||||
{
|
||||
/**
|
||||
* Any state stored by the concrete flyweight must be independent of its context.
|
||||
* For flyweights representing characters, this is usually the corresponding character code.
|
||||
@@ -32,5 +32,4 @@ class CharacterFlyweight implements FlyweightInterface {
|
||||
{
|
||||
print_r("Character {$this->name} printed $font \n");
|
||||
}
|
||||
|
||||
}
|
@@ -8,8 +8,8 @@ use DesignPatterns\Structural\Flyweight\CharacterFlyweight;
|
||||
* A factory manages shared flyweights. Clients shouldn't instaniate them directly,
|
||||
* but let the factory take care of returning existing objects or creating new ones.
|
||||
*/
|
||||
class FlyweightFactory {
|
||||
|
||||
class FlyweightFactory
|
||||
{
|
||||
/**
|
||||
* Associative store for flyweight objects
|
||||
* @var Array
|
||||
@@ -23,15 +23,14 @@ class FlyweightFactory {
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if (!array_key_exists((string) $name, $this->pool)) {
|
||||
$this->pool[(string) $name] = new CharacterFlyweight((string) $name);
|
||||
if (!array_key_exists($name, $this->pool)) {
|
||||
$this->pool[$name] = new CharacterFlyweight($name);
|
||||
}
|
||||
return $this->pool[(string) $name];
|
||||
return $this->pool[$name];
|
||||
}
|
||||
|
||||
public function totalNumber()
|
||||
{
|
||||
return sizeof($this->pool);
|
||||
}
|
||||
|
||||
}
|
@@ -5,8 +5,7 @@ namespace DesignPatterns\Structural\Flyweight;
|
||||
/**
|
||||
* An interface through which flyweights can receive and act on extrinsic state
|
||||
*/
|
||||
interface FlyweightInterface {
|
||||
|
||||
interface FlyweightInterface
|
||||
{
|
||||
public function draw($extrinsicState);
|
||||
|
||||
}
|
Reference in New Issue
Block a user