【最速】google guice DI Framework【シンプル】at TECH
【最速】google guice DI Framework【シンプル】 - 暇つぶし2ch61:1
07/03/25 21:58:52
>>60
なるほど。それならこれでいけるかな。
ただ、その処理やるならkeyとクラス名を紐付けといてリフレクションで呼んだ方が楽かと。。
 public interface IfCommand {
  public void exec();
 }
 public OneTimeExecCommand implements IfCommand{
  public void exec(){何かの処理}
 }
 public TwoTimeExecCommand implements IfCommand{
  public void exec(){何かの処理}
 }
 public class MyModule implements Module {
  public void configure(Binder binder){
   binder.bind(IfCommand.class).to(OneTimeExecCommand.class)
    .annotatedWith(OneTimeExec.class).in(Scopes.SINGLETON)
   binder.bind(IfCommand.class).to(TwoTimeExecCommand.class)
    .annotatedWith(TwoTimeExec.class).in(Scopes.SINGLETON)
  }
 }
 pulic class CommandProcessor {
  private @Inject @OneTimeExec IfCommand oneTimeExec;
  private @Inject @TwoTimeExec IfCommand twoTimeExec;
  public process(){
   switch(key){
   case 1:
    oneTimeExec.exec();
   case 2:
    tweTimeExec.exec();
   }
 }


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch