Last active
October 8, 2016 05:54
-
-
Save pospome/21c359eb7a70313a2bf3f99586df008e to your computer and use it in GitHub Desktop.
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 | |
// State を生成するだけの factory | |
// 生成するクラスが複雑になる場合は abstract factory を利用すると良い | |
class StateFactory { | |
public static function Create(type){ | |
if type == 1 { | |
return new State1(); | |
} | |
return new State2(); | |
} | |
} | |
// 以下のように利用する | |
$s = StateFactory::Create(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment