Skip to content

Instantly share code, notes, and snippets.

@mlebkowski
Created September 26, 2013 14:56
Show Gist options
  • Save mlebkowski/6715375 to your computer and use it in GitHub Desktop.
Save mlebkowski/6715375 to your computer and use it in GitHub Desktop.
<?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