ファクトリの取得方法
うーんC++で下のようなコードの書き方がわからん・・・
import java.util.Map; public abstract class Base { static Map<String, Factory> map; static { map.put("foo", new Foo.FooFactory()); map.put("bar", new Bar.BarFactory()); } static Base create(String target) { for (Map.Entry<String, Factory> entry : Base.map.entrySet()) { if (target.equals(entry.getKey())) { return entry.getValue().create(); } } return null; } public abstract String getType(); } interface Factory { Base create(); } class Foo extends Base { static class FooFactory implements Factory { public Foo create() { return new Foo(); } } public String getType() { return "foo"; }; } class Bar extends Base { static class BarFactory implements Factory { public Bar create() { return new Bar(); } } public String getType() { return "bar"; }; } class Main { public static void main(String[] args) { Base base = Base.create("bar"); System.out.println(base.getType()); } }