Created
September 26, 2013 14:56
-
-
Save mlebkowski/6715375 to your computer and use it in GitHub Desktop.
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
<?php | |
interface Discount | |
{ | |
/** | |
* @return int | |
*/ | |
function getDiscountValue(Order $order); | |
} | |
class CalendarDiscount implements Discount | |
{ | |
function getDiscountValue(Order $order) | |
{ | |
if ($order…) | |
return 5; | |
return 0; | |
} | |
} | |
class Order { | |
protected $discount = []; | |
function applyDiscount(Discount $discount) { | |
$value = $discount->getDiscountValue($this); | |
if ($value) { | |
$this->discount[] = $value; | |
} | |
} | |
function getPrice() { | |
return $this->price * (1 - array_sum($this->discount)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment