Low cost ecommerce web development India flash website design
Composition
Composition occurs when one object “completely owns” another object. That is,
the first object was responsible for creating (instantiating) the second object.
There are many cases in which this can be useful, although, typically, composition
is used when it's likely that the first object will be the only one that needs to use
the second object.
One example from Volume II, Chapter 1 is the Auth class, which composes an
instance of the Session class, creating it in the constructor:
class Auth {
…
/**
* Instance of Session class
* @var Session
*/
var $session;
…
function Auth (&$dbConn, $redirect, $md5 = true)
{
$this->dbConn = &$dbConn;
$this->redirect = $redirect;
$this->md5 = $md5;
$this->session = &new Session();
$this->checkAddress();
$this->login();
}
Because the Auth class needs to read and write to session variables, and only a
limited number of other, unrelated classes in an application are likely also to
need to use Session, it's logical that it gets to create its own Session object.
website designer freelance ASP PHP ecommerce web developer
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110