观察者模式

源代码在线查看: phonenumber.java

软件大小: 3 K
上传用户: jccg1000146752
关键词: 模式
下载地址: 免注册下载 普通下载 VIP

相关代码

				package Observe;
				
				import java.util.Observable;
				
				public class PhoneNumber extends Observable {
					private Long phoneNumber;
					private double bill;
					/**
					 * @return the phoneNumber
					 */
					public Long getPhoneNumber() {
						return phoneNumber;
					}
					/**
					 * @param phoneNumber the phoneNumber to set
					 */
					public void setPhoneNumber(Long phoneNumber) {
						this.phoneNumber = phoneNumber;
				
					}
					/**
					 * @return the bill
					 */
					public double getBill() {
						return bill;
					}
					/**
					 * @param bill the bill to set
					 */
					public void setBill(double bill) {
						this.bill = bill;
						this.setChanged();
						this.notifyObservers(bill);
					}
					public PhoneNumber(){
				
						this.addFriend(new Friend("Tom"));
						this.addFriend(new Friend("Jack"));
						this.addFriend(new Friend("Mike"));
					}
				    public void addFriend(Friend f){
				    	super.addObserver(f);
				    }
				    public void setNumber(Long phoneNumber){
				    	this.phoneNumber=phoneNumber;
				    	this.setChanged();//设置监控点
				    	this.notifyObservers(phoneNumber);
				    }
				    
				}
							

相关资源