Last active
March 24, 2016 12:39
-
-
Save actorius/8d4d121d9ea171a60ba0 to your computer and use it in GitHub Desktop.
Goods
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
interface IGood { | |
public $title; | |
public $price; | |
public GetPrice(); | |
} | |
class OriginalGood implements IGood { | |
public $title; | |
public $price; | |
function __construct() { ... } | |
public GetPrice(){ | |
return $this->price; | |
} | |
} | |
class SaleGood implements IGood { | |
public $title; | |
public $price; | |
function __construct() { ... }; | |
public GetPrice(){ | |
$discount = $this->calculateDiscount(); | |
return $this->price * $this->discount; | |
} | |
public calculateDiscount() { | |
... | |
} | |
} | |
class Cart { | |
public $goods = []; | |
private SetReserved($good) { | |
//Резервация заказа на какое-то время. | |
App::DB->Goods->setReserved($good->id, "10000"); | |
} | |
public AddGoodsToShowCase($good) { | |
$this->goods[] = $good; | |
$this->SetReserved($good); | |
} | |
public GetTotalPrice() { | |
$price = 0; | |
if (count($this->goods) > 3) { | |
foreach($this->goods as $good) { | |
$price += $good->GetPrice(); | |
} | |
} | |
return $price * $this->_discount; | |
} | |
} | |
$cart = new Cart; | |
$sGood = new SaleGood; | |
$oGood = new OriginalGood; | |
$cart->AddGoodsToShowCase($sGood); | |
$cart->AddGoodsToShowCase($oGood); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment