mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-09 16:36:37 +02:00
fixed eol and typecast
This commit is contained in:
@@ -10,23 +10,23 @@ use DesignPatterns\Structural\Flyweight\FlyweightFactory;
|
||||
*/
|
||||
class FlyweightTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $characters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
|
||||
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
|
||||
private $fonts = array('Arial', 'Times New Roman', 'Verdana', 'Helvetica');
|
||||
private $characters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
|
||||
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
|
||||
private $fonts = array('Arial', 'Times New Roman', 'Verdana', 'Helvetica');
|
||||
|
||||
// This is about the number of characters in a book of average length
|
||||
private $numberOfCharacters = 300000;
|
||||
// This is about the number of characters in a book of average length
|
||||
private $numberOfCharacters = 300000;
|
||||
|
||||
public function testFlyweight()
|
||||
{
|
||||
$factory = new FlyweightFactory();
|
||||
|
||||
for ($i = 0; $i < $this->numberOfCharacters; $i++) {
|
||||
$char = $this->characters[array_rand($this->characters)];
|
||||
$font = $this->fonts[array_rand($this->fonts)];
|
||||
$flyweight = $factory->$char;
|
||||
// External state can be passed in like this:
|
||||
// $flyweight->draw($font);
|
||||
$char = $this->characters[array_rand($this->characters)];
|
||||
$font = $this->fonts[array_rand($this->fonts)];
|
||||
$flyweight = $factory->$char;
|
||||
// External state can be passed in like this:
|
||||
// $flyweight->draw($font);
|
||||
}
|
||||
|
||||
// Flyweight pattern ensures that instances are shared
|
||||
|
Reference in New Issue
Block a user