1类图
2java示例
{ main([] args) { Plane plane Plane(); Observer observer Radar(); plane.addObserver(observer); plane.setDistance(); } }
Observable { name; Plane( name){ .namename; } getName() { name; } setDistance( distance){ (distance){ .setChanged(); .notifyObservers(); } } }
Observer { update(Observable o, arg) { Plane plane(Plane)o; System.out.println(plane.getName()); } }