*/
public void add(Observer observer);
/**
- 通知
*/
public void notice();
/**
- 前台状态
*/
public String getAction();
public void setAction(String action);
}
package com.oop.demo3;
/**
- 定义股票观察员对象
- @author Liudeli
*/
public class StockObserver extends Observer{
private String name;
private ISecretary secretary;
public StockObserver(String name, ISecretary secretary) {
super(name, secretary);
this.name = name;
this.secretary = secretary;
}
@Override
public void update() {
System.out.println(secretary.getAction() + name + " 请你关闭股票行情,继续工作");
}
}
package com.oop.demo3;
/**
- 定义看NBA的同事
- @author Liudeli
*/
public class NBAObserver extends Observer {
private String name;
private ISecretary secretary;
public NBAObserver(String name, ISecretary secretary) {
super(name, secretary);
this.name = name;
this.secretary = secretary;
}
@Override
public void update() {
System.out.println(secretary.getAction() + name + " 请你关闭NBA视频画面,继续工作");
}
}
package com.oop.demo3;
import java.util.ArrayList;
import java.util.List;
/**
- 前台秘书类
- @author Liudeli
*/
public class Secretary implements ISecretary{
/**
- 定义同事集合
*/
private List list = new ArrayList(); <