Created
December 11, 2013 00:54
-
-
Save patrioticcow/7903279 to your computer and use it in GitHub Desktop.
Strategy Pattern
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
abstract class FileNamingStrategy { | |
abstract function createLinkName($filename); | |
} | |
class ZipFileNamingStrategy extends FileNamingStrategy { | |
function createLinkName($filename) | |
{ | |
return "http://downloads.foo.bar/$filename.zip"; | |
} | |
} | |
class TarGzFileNamingStrategy extends FileNamingStrategy { | |
function createLinkName($filename) | |
{ | |
return "http://downloads.foo.bar/$filename.tar.gz"; | |
} | |
} | |
if (strstr($_SERVER["HTTP_USER_AGENT"], "Win")) { | |
$fileNamingObj = new ZipFileNamingStrategy(); | |
} else { | |
$fileNamingObj = new TarGzFileNamingStrategy(); | |
} | |
$calc_filename = $fileNamingObj->createLinkName("Calc101"); | |
$stat_filename = $fileNamingObj->createLinkName("Stat2000"); | |
print <<<EOF | |
<h1>The following is a list of great downloads<</h1> | |
<br> | |
<a href="$calc_filename">A great calculator</a><br> | |
<a href="$stat_filename">The best statistics application</a><br> | |
<br> | |
EOF; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment