/*
观察者抽象类
更新信息
*/
public interface DingLZhe {
void upbu(String xx);
}
@Data
public class DingZheUSE implements DingLZhe {
private String XinXi="";
private String name;
public DingZheUSE(String name) {
this.name = name;
}
@Override
public void upbu(String xx) {
XinXi=xx;
System.out.println(name+"信息已更新");
}
}
//被观察对象
//添加观察者对象,与修改观察者对象信息
public interface XiaoCengXu {
List<DingLZhe> dz=new ArrayList<>();
void update(String xx);
void add(DingLZhe dz);
}
public class XiaoCengXuUSE implements XiaoCengXu{
@Override
public void update(String xx) {
for(DingLZhe daz:dz){
daz.upbu(xx);
}
}
@Override
public void add(DingLZhe dsz) {
dz.add(dsz);
}
}