-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Single Responsibility Principle, SRP
- Loading branch information
1 parent
4119f93
commit b985b70
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
/** | ||
* SOLID | ||
* | ||
* S - Single Responsibility Principle, SRP | ||
*/ | ||
|
||
$product = new Product(); | ||
$product->setPrice(10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* SOLID | ||
* | ||
* S - Single Responsibility Principle, SRP | ||
*/ | ||
|
||
class Logger | ||
{ | ||
public function log($message) | ||
{ | ||
// ... | ||
$this->saveToFile($message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* SOLID | ||
* | ||
* S - Single Responsibility Principle, SRP | ||
*/ | ||
|
||
class Product | ||
{ | ||
/** | ||
* @param float $price | ||
*/ | ||
public function setPrice($price) | ||
{ | ||
try { | ||
// save price | ||
} catch (Exception $e) { | ||
$this->log($e->getMessage()); | ||
} | ||
} | ||
|
||
public function log($message) | ||
{ | ||
// log message to storage | ||
} | ||
} |