??????HTTPS???????
???????? ???????[ 2016/12/26 11:44:27 ] ??????????????? https
??????????? Observer
???????????????????????????????????????????????????????????????
????????????????????????仯??????????й????????????????????????????
????????????????
?????????????? ???????ж??????????????????????????У??????????????????????????????????????????????????????????????????????????????????????????????????
?????????????? ??????о???????????????????????????????????????
?????????????? ???????????????????????????е??????????????????????????????????????????
?????????????? ???y????????????????????????????????????????????????Э?????????????????????????????????????????????????????????????????á?
???????????
????????????????????????????
????????????????????
//??????????
public interface Watcher
{
public void update(String str);
}
??????????????????????????????????????????????????????????????????????????
//????????????watched???????
public interface Watched
{
public void addWatcher(Watcher watcher);
public void removeWatcher(Watcher watcher);
public void notifyWatchers(String str);
}
??????????????????
public class ConcreteWatcher implements Watcher
{
@Override
public void update(String str)
{
System.out.println(str);
}
}
?????????????????????
import java.util.ArrayList;
import java.util.List;
public class ConcreteWatched implements Watched
{
// ???????
private List<Watcher> list = new ArrayList<Watcher>();
@Override
public void addWatcher(Watcher watcher)
{
list.add(watcher);
}
@Override
public void removeWatcher(Watcher watcher)
{
list.remove(watcher);
}
@Override
public void notifyWatchers(String str)
{
// ????????????????????е????
for (Watcher watcher : list)
{
watcher.update(str);
}
}
}
??????д??????
public class Test
{
public static void main(String[] args)
{
Watched girl = new ConcreteWatched();
Watcher watcher1 = new ConcreteWatcher();
Watcher watcher2 = new ConcreteWatcher();
Watcher watcher3 = new ConcreteWatcher();
girl.addWatcher(watcher1);
girl.addWatcher(watcher2);
girl.addWatcher(watcher3);
girl.notifyWatchers("????");
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11