是否可以采用类似Observer 模式来处理Game 类作为一个主题,而另外一个Observer来记录所有game的运行情况,每一个Game 在实例化的时候产生一个唯一的标识,然后再运行时、运行结束后在Observer中登记运行状态,Observer 中可以用HashMap来存放Games的运行状态 map.put(game.getID, game.status)
如下面
构造方法中
public Game() {
//产生一个唯一ID
}
public void startGame(){
try {
//notify observer:Game(ID) is Stated....
process = Runtime.getRuntime().exec(this.exePath);
process.waitFor(); //wait the process to terminate
//notify observer: Game(ID) is terminated
}
catch (Exception ex) {
//notify observer:Game(ID) is terminated
ex.printStackTrace();
}
}
/**
* 判断这个程序是否在运行
* @return
*/
public boolean isRuning(){
//get the status of the Game(ID) from observer
}