Last active
August 29, 2015 14:02
-
-
Save vonglasow/f04535323efab24f1e54 to your computer and use it in GitHub Desktop.
Factory
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 Factory | |
{ | |
public function create() | |
{ | |
$this->context->create(); | |
} | |
public function setContext($context) | |
{ | |
$this->context = $context; | |
} | |
} | |
SlotsInterface { | |
public function create(); | |
} | |
class OW implements SlotsInterface | |
{ | |
public function create() | |
{ | |
echo 'create two slots' . PHP_EOL; | |
} | |
} | |
class AR implements SlotsInterface | |
{ | |
public function create() | |
{ | |
echo 'Create four slots' . PHP_EOL; | |
} | |
} | |
//Usage | |
$f = new Factory(); | |
$f->setContext(new AR()); | |
$f->create(); // Four slots created | |
$f->setContext(new OW()); | |
$f->create(); // two slots created |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment