Skip to content

Instantly share code, notes, and snippets.

@mewm
Created April 12, 2016 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mewm/20262da17cc153f400018440a3be0184 to your computer and use it in GitHub Desktop.
Save mewm/20262da17cc153f400018440a3be0184 to your computer and use it in GitHub Desktop.
SOLID made simple
<?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