Last active
August 29, 2015 14:21
-
-
Save kandran/4b1f80698da9bad8602b to your computer and use it in GitHub Desktop.
Design pattern stratégie (http://kandran.fr/design-pattern-strategie/)
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 | |
require_once("ApplicationInterface.php"); | |
class ApplicationA implements ApplicationInterface{ | |
public function run() | |
{ | |
echo "<br/> Application A start running"; | |
//some computation | |
echo "<br/> Application A finished"; | |
} | |
} |
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 | |
require_once("ApplicationInterface.php"); | |
class ApplicationB implements ApplicationInterface{ | |
public function run() | |
{ | |
echo "<br/> Application B start running"; | |
//some other computation | |
echo "<br/> Application B finished"; | |
} | |
} |
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 | |
interface ApplicationInterface | |
{ | |
public function run(); | |
} |
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 | |
require_once("ApplicationInterface.php"); | |
class ApplicationStarter{ | |
public function startApplication(ApplicationInterface $application) | |
{ | |
$application->run(); //here we don't know the class name of application | |
} | |
} |
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 | |
require_once("ApplicationA.php"); | |
require_once("ApplicationB.php"); | |
require_once("ApplicationStarter.php"); | |
$applicationStarterObject = new ApplicationStarter(); | |
$application1 = new ApplicationA(); | |
$application2 = new ApplicationB(); | |
$application3 = new ApplicationA(); | |
$applicationsToRun = array($application1, $application2 , $application3); | |
foreach($applicationsToRun as $application){ | |
$applicationStarterObject->startApplication($application); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment