Skip to content

Instantly share code, notes, and snippets.

@AlexGalhardo
Created August 24, 2019 21:32
Show Gist options
  • Select an option

  • Save AlexGalhardo/38015d4ad2c1ae2bd6aafe3285fdfb54 to your computer and use it in GitHub Desktop.

Select an option

Save AlexGalhardo/38015d4ad2c1ae2bd6aafe3285fdfb54 to your computer and use it in GitHub Desktop.
<?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...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment