Example #1
0
// "ConcreteFlyweight"
class CharacterZ extends Character
{
    // Constructor
    public function __construct()
    {
        $this->symbol = 'Z';
        $this->height = 100;
        $this->width = 100;
        $this->ascent = 68;
        $this->descent = 0;
    }
    public function Display($pointSize)
    {
        $this->pointSize = $pointSize;
        print $this->symbol . " (pointsize " . $this->pointSize . ")";
    }
}
$document = "AAZZBBZB";
// Build a document with text
$chars = str_split($document);
print_r($chars);
$f = new CharacterFactory();
// extrinsic state
$pointSize = 0;
// For each character use a flyweight object
foreach ($chars as $key) {
    $pointSize++;
    $character = $f->GetCharacter($key);
    $character->Display($pointSize);
}
Example #2
0
 public function register($name, $atk, $rank)
 {
     $this->character = CharacterFactory::create($name, $atk, $rank);
 }