Skip to content

Instantly share code, notes, and snippets.

@netkiller
Last active August 29, 2015 13:58
Show Gist options
  • Save netkiller/10347249 to your computer and use it in GitHub Desktop.
Save netkiller/10347249 to your computer and use it in GitHub Desktop.
Withdrawal
<?php
class Withdrawal{
public $money = 0;
function __construct($money){
$this->money = $money;
}
public function total(){
return $this->money;
}
}
class Fee{
function __construct($withdrawal, $item) {
$withdrawal->money = $withdrawal->money - $item->money;
}
}
class Bounty{
function __construct($money){
$this->money = $money;
}
}
class OldBounty{
function __construct($money){
$this->money = $money;
}
}
class Money {
function __construct($money){
$this->money = $money;
}
function getMoney(){
return $this->money;
}
}
class Exchange {
function __construct($money, $item) {
$money->money = $money->getMoney() * $item->rate;
}
}
class USD {
public $rate = 6.5;
function __construct(){
}
}
class HKD {
private $rate = 1.5;
function __construct(){
}
}
class RMB {
private $rate = 3.5;
function __construct(){
}
}
$withdrawal = new Withdrawal(100);
$fee = new Fee($withdrawal, new Bounty(20));
$fee = new Fee($withdrawal, new OldBounty(10));
printf("%f \n",$withdrawal->total());
$money = new Money($withdrawal->total());
$exchange = new Exchange($money, new USD());
printf("%f \n",$money->getMoney());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment