-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSmallPackage.php
More file actions
46 lines (40 loc) · 942 Bytes
/
SmallPackage.php
File metadata and controls
46 lines (40 loc) · 942 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
45
46
<?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 small package is
* instantiated.
*
* @author Vlad Riabchenko <contact@vria.eu>
*/
class SmallPackage implements PackageInterface
{
/**
* Intrinistic state that can be shared.
* @var string
*/
private $name = 'Small';
/**
* Intrinistic state that can be shared.
* @var int
*/
private $volume = 2;
/**
* @inheritdoc
*/
public function getName()
{
return $this->name;
}
/**
* The total weight is always a multiple of 5: 8 -> 10, 41 -> 45.
*
* @inheritdoc
*/
public function getTotalWeight($density)
{
$nominalWeight = $this->volume * $density;
return $nominalWeight + (5 - $nominalWeight % 5);
}
}