-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaceSegregationPrinciple.php
More file actions
44 lines (38 loc) · 1.4 KB
/
InterfaceSegregationPrinciple.php
File metadata and controls
44 lines (38 loc) · 1.4 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
<?php
/***************************************************************
*A client should never be forced to implement an interface *
*that does not use or a client should not forced to depend on *
*methods that they do not use. *
***************************************************************
*/
/*
* Violation of open closed
*/
interface BaseInterface
{
public function getAll();
public function getById($id);
public function create($data);
public function update($id, $data);
public function delete($id);
}
// There is nothing wrong with this baseInterface implementation.
// Lets assume that we have two model name user and customers
// The user model will implement the baseInterface.There is nothing wrong
// with this implementation.But the problem is customers model will not.
// so we have to implement the baseInterface in the customers model which is not good.
// so we can do two separate interface one for readOnly ,another for writeOnly.
//Refactoring the code
interface ReadOnlyInterface
{
public function getAll();
public function getById($id);
}
interface WriteOnlyInterface
{
public function create($data);
public function update($id, $data);
public function delete($id);
}
// now the problem is solved. user and customer can implements the interface as required and
// none is forced to implement the interface that does not use