-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRP_02.php
56 lines (44 loc) · 1.18 KB
/
SRP_02.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
<?php
class Product
{
private $name;
private $price;
private $description;
public function __construct($name, $price, $description)
{
$this->name = $name;
$this->price = $price;
$this->description = $description;
}
// getters and setters for name, price, and description
/* This violates the srp because the class has multiple responsibilities.
To apply the srp, we can separate the responsibilities into separate classes.
public function saveToDatabase() {
// logic for saving the product to the database
}
public function displayProduct() {
// logic for displaying the product on a web page
}
public function deleteFromDatabase() {
// logic for deleting the product from the database
}
*/
}
class ProductRepository
{
public function saveProduct($product)
{
// logic for saving the product to the database
}
public function deleteProduct($product)
{
// logic for deleting the product from the database
}
}
class ProductRenderer
{
public function renderProduct($product)
{
// logic for displaying the product on a web page
}
}