-
Notifications
You must be signed in to change notification settings - Fork 0
/
SOLID.php
117 lines (101 loc) · 2.19 KB
/
SOLID.php
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
111
112
113
114
115
116
117
<?php
class Reporter{
public $data = [100,200,300,400,500];
public function report($price, Formatter $f){
$arr = $this->greaterThan($price);
return $f->parse($arr);
}
public function greaterThan($price){
return array_filter($this->data, function ($item) use ($price){
return $item > $price;
});
}
}
interface Formatter{
public function parse($arr);
}
class JsonFormatter implements Formatter {
public function parse($arr){
return json_encode($arr);
}
}
class ArrayFormatter implements Formatter {
public function parse($arr){
return $arr;
}
}
$formatter = new JsonFormatter();
$reporter = new Reporter();
$reporter->report(200, $formatter);
class Order{
public function process(ProductProcessing $product)
{
$this->state = $product->perform();
}
}
interface ProductProcessing{
public function perform();
}
class NormalProductProcessing implements ProductProcessing {
public $queue;
public function perform()
{
$this->queue = true;
}
}
class SpecificProductProcessing implements ProductProcessing {
public $queue;
public function perform()
{
$this->queue = false;
}
}
abstract class FlyingBird{
abstract function fly();
}
abstract class NonFlyingBird{
abstract function drink();
}
class Eagle extends Bird{
public function fly(){
return 'Flying....';
}
}
class Duck extends NonFlyingBird {
// public function fly(){
// throw new Exception('I am not able');
// }
}
//interface Workable{
// public function sleep();
// public function wakeUp();
//}
interface sleep{
public function sleeping();
}
interface waking{
public function wakeUp();
}
class Human implements waking,sleep {
public function sleep(){
}
public function wakeUp(){
}
}
class Robot implements waking {
// public function sleep(){
//
// }
public function wakeUp(){
}
}
class FilterData{
public $connection;
public function __construct(Sqlite $mysqConn)
{
$this->connection = $mysqConn;
}
public function selecQuery($query){
return $this->connection->select($query);
}
}