Skip to content

Instantly share code, notes, and snippets.

@actorius
Last active March 24, 2016 12:39
Show Gist options
  • Save actorius/8d4d121d9ea171a60ba0 to your computer and use it in GitHub Desktop.
Save actorius/8d4d121d9ea171a60ba0 to your computer and use it in GitHub Desktop.
Goods
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