-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcomposition.php
More file actions
64 lines (54 loc) · 1.14 KB
/
Copy pathcomposition.php
File metadata and controls
64 lines (54 loc) · 1.14 KB
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
<?php
/**
* This example just to simulate how Composition can be work
* 2nees.com
*/
class Person {
private Heart $heart;
private Brain $brain;
/**
* Person constructor.
* @param Heart $heart
* @param Brain $brain
*/
public function __construct(Heart $heart, Brain $brain)
{
$this->heart = $heart;
$this->brain = $brain;
}
public function printPersonDetails(): void {
echo "
Heart is {$this->heart->getStatus()} And
Brain is {$this->brain->getStatus()}
";
}
}
abstract class Members {
private string $status;
/**
* Heart constructor.
* @param string $status
*/
public function __construct(string $status)
{
$this->status = $status;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
}
class Heart extends Members {
// Do any thing...
}
class Brain extends Members {
// Do any thing...
}
// Client
$heart = new Heart("Strong");
$brain = new Brain("Smart");
$person = new Person($heart, $brain);
$person->printPersonDetails();