Skip to content

Commit

Permalink
Single Responsibility Principle, SRP
Browse files Browse the repository at this point in the history
  • Loading branch information
maximgubar committed Oct 22, 2015
1 parent 4119f93 commit b985b70
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions s/index.php
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);
15 changes: 15 additions & 0 deletions s/logger.php
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);
}
}
26 changes: 26 additions & 0 deletions s/product.php
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
}
}

0 comments on commit b985b70

Please sign in to comment.