<?php
final class StaticFactory {
public static function make($type) {
if($type == 'number'){
return new FormatNumber();
}
if($type == 'string'){
return new FormatString();
}
}
}
interface FormatterInterface {
public function format($n);
}
class FormatNumber implements FormatterInterface {
public function format($n){
echo 'Formatando numero: '. $n;
}
}
class FormatString implements FormatterInterface {
public function format($n){
echo 'Formatando string: ' . $n;
}
}
$formatter = StaticFactory::make('string');
$formatter->format('testando 1, 2, 3...');
Created
August 24, 2019 21:32
-
-
Save AlexGalhardo/38015d4ad2c1ae2bd6aafe3285fdfb54 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment