public static void main(String[] args) { Boss Boss = new Boss("老板", "在办公室"); Guard guard = new Guard("前台"); Boss.addObserver(guard); Boss.getState(); Boss.setState("离开了"); Boss.setState("回来了"); }
@Override public void update(Observable o, Object arg) { Boss boss = (Boss) o; System.out.println(this.getName() + "报告" + boss.getName() + boss.getState()); }