-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBigPackage.php
More file actions
44 lines (39 loc) · 904 Bytes
/
Copy pathBigPackage.php
File metadata and controls
44 lines (39 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace DesignPatterns\Structural\Flyweight;
/**
* Concrete flyweight.
* This is a shared object that allows a certain economy of memory.
* @see PackageFactory ensures that only one instance of big package is
* instantiated.
*
* @author Vlad Riabchenko <contact@vria.eu>
*/
class BigPackage implements PackageInterface
{
/**
* Intrinistic state that can be shared.
* @var string
*/
private $name = 'Big';
/**
* Intrinistic state that can be shared.
* @var int
*/
private $volume = 20;
/**
* @inheritdoc
*/
public function getName()
{
return $this->name;
}
/**
* The total mass grows as fast as a (linear + logarithmic) function.
*
* @inheritdoc
*/
public function getTotalWeight($density)
{
return ceil($this->volume * $density * (1 + log($density, 10)));
}
}