Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
Forked from giovanisilveira/factory.php
Last active August 29, 2015 14:02
Show Gist options
  • Save leocavalcante/642d035c5d5715191c04 to your computer and use it in GitHub Desktop.
Save leocavalcante/642d035c5d5715191c04 to your computer and use it in GitHub Desktop.
<?php
interface Support {}
class TechnicalSupport implements Support {}
class FinancialSupport implements Support {}
class AdministrativeSupport implements Support {}
class SupportFactory
{
public function createByType($type)
{
$class = $type.'Support';
if (!class_exists($class)) {
throw new InvalidArgumentException("there is no class $class");
}
return new $class;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment