Skip to content

Instantly share code, notes, and snippets.

@pospome
Last active October 8, 2016 05:54
Show Gist options
  • Save pospome/21c359eb7a70313a2bf3f99586df008e to your computer and use it in GitHub Desktop.
Save pospome/21c359eb7a70313a2bf3f99586df008e to your computer and use it in GitHub Desktop.
<?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