public interface Subject {
public void registerObserver(Observer o); //옵저버로 등록하기 위해
public void removeObserver(Observer o); //옵저버를 제거하기 위해
public void notifiyObservers(); //옵저버들한테 알리기 위해
}
public class Newspaper implements Subject{
LinkedList<Observer> observers = new LinkedList<Observer>();
private Content c;
public Newspaper(Content c) {
// TODO Auto-generated constructor stub
this.c = c;
}
@Override
public void registerObserver(Observer o) {
// TODO Auto-generated method stub
observers.add(o);
}
@Override
public void removeObserver(Observer o) {
// TODO Auto-generated method stub
observers.remove(o);
}
@Override
public void notifiyObservers() {
// TODO Auto-generated method stub
for (Observer o : observers) {
o.update(new Date(), c);
}
}
}
public interface Observer {
public void update(Date date, Content content);
}
public class ForeignPerson implements Observer{
@Override
public void update(Date date, Content content) {
// TODO Auto-generated method stub
}
}
//옵저버 클래스1
public class DomesticPerson implements Observer{
@Override
public void update(Date date, Content content) {
// TODO Auto-generated method stub
}
}