tailieunhanh - head first design patterns phần 10

một sự sụt giảm nhanh chóng Trip to Objectville: có, sẽ được các đối tượng biết biến: nguyên thủy và tài liệu tham khảo Làm thế nào các đối tượng Ứng xử: đối tượng nhà nước ảnh hưởng đến phương pháp hành vi Extra-Strength phương pháp kiểm soát dòng chảy, hoạt động, và nhiều hơn nữa Sử dụng thư viện Java: | ready-bake COÙ heart beat model notifyBeatObservers0 if rate lastrate lastrate rate notifyBPMObservers 0 try time catch Exception e I public int getHeartRate return 60000 time ReaHy-baXe- Code public void registerobserver Beatobserver o o public void removeobserver Beatobserver o int i o if i - 0 i J public void notifyBeatObservers0 for inc i 0 i i Beatobserver observer - Beatobserver i public void registerobserver BPMObserver o o public void removeobserver BPMObserver o int i o if i - 0 i public void notifyBPMObservers0 for int i 0 i 0 i BPMObserver observer BPMObserver i 574 Chapter 12 compound patterns The Heart Adapter package headfirst. combined. djview public class HeartAdapter implements BeatModellnterface HeartModelInterface heart public HeartAdapter HeartModellnterface heart - heart public void initialize 0 public void on public void off public int getBPMO return I public void setBPM int bpm public void registerobserver Beatobserver o o public void removeobserver Beatobserver o o public void registerobserver BPMObserver o o public void removeobserver BPMObserver o o you are here 575 ready-bake code heart beat controller The Controller Ready-baX Code package headfirst . public class Heartcontroller implements Controllerinterface HeartModellnterface model DJView view public Heartcontroller HeartModellnterface model model view - new DJView this new HeartAdapter model 0 public void start 0 public void stopO public void increaseBPM public void decreaseBPM public void setBPM int bpm 576 Chapter