| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 
 |  
/* Contexte d'une action*/
class Context {
}
 
/* Definition interface d'une réponse */
interface Response {
  void process(Context ctxt);
}
 
/* Implementation des réponses de chaque action */
class Connecter implements Response {
  void process(Context ctxt) {
  }
}
 
class Deconnecter implements Response {
  void process(Context ctxt) {
  }
}
 
class Commencer implements Response {
 {
  void process(Context ctxt) {
  }
}
 
class Finir implements Response {
  void process(Context ctxt) {
  }
}
 
 
/* */
class Processing {
  public static final String ACTION_CONNECTER = "connecter";
  public static final String ACTION_DECONNECTER = "deconnecter";
  public static final String ACTION_COMMENCER = "commencer";
  public static final String ACTION_FINIR = "finir";
 
  Map actions = new HashMap();
 
  public Processing() {
    /* On instancie chaque réponse */
    actions.put(ACTION_CONNECTER, new Connecter());
    actions.put(ACTION_DECONNECTER, new DeConnecter());
    actions.put(ACTION_COMMENCER, new Commencer());
    actions.put(ACTION_FINIR, new Finir());
  }
 
  /* On traite les actions */
  public process() {
    Context ctxt = new Context(ctxt);
 
    while (true) {
      String msg = socket.recoitMessage();
      Response response = (Response)actions.get(msg);
      if (response != null) {
        response.process(ctxt);
      }
    }
  } |