Created
April 12, 2016 22:00
-
-
Save mewm/20262da17cc153f400018440a3be0184 to your computer and use it in GitHub Desktop.
SOLID made simple
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 | |
class ATM | |
{ | |
public function __construct() | |
{ | |
} | |
public function withdrawByCard() | |
{ | |
echo 'widthraw by card'; | |
} | |
public function widthrawByFingerprint() | |
{ | |
echo 'widthraw by fingerprint'; | |
} | |
} | |
$_atm = new ATM(); | |
$_atm->widthrawByFingerprint(); | |
class ATM | |
{ | |
private $withdrawMethod; | |
public function __construct(WithdrawMethod $withdrawMethod) | |
{ | |
$this->withdrawMethod = $withdrawMethod; | |
} | |
public function withdraw() | |
{ | |
$this->withdrawMethod->withdrawByMethod(); | |
} | |
} | |
interface WithdrawMethod | |
{ | |
public function withdrawByMethod(); | |
} | |
class FingerprintWithdrawMethod implements WithdrawMethod | |
{ | |
public function withdrawByMethod() | |
{ | |
echo 'withdraw by fingerprint'; | |
} | |
} | |
class CardWithdrawMethod implements WithdrawMethod | |
{ | |
public function withdrawByMethod() | |
{ | |
echo 'withdraw by card'; | |
} | |
} | |
$_withdrawMethod = new FingerprintWithdrawMethod(); | |
$_atm = new ATM($_withdrawMethod); | |
$_atm->withdraw(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment