Observer PatternAlbert Guojunyuo@gmail.com1
MotivationIntentImplementationApplicability & ExamplesAgenda2
Let's assume we have a stock system which provides data for several types of client. We want to have a client implemented as a web based application but in near future we need to add clients for mobile devices, Palm or Pocket PC, or to have a system to notify the users with sms alerts. Now it's simple to see what we need from the observer pattern: we need to separate the subject(stocks server) from it's observers(client applications) in such a way that adding new observer will be transparent for the server.Motivation3
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.Intent4
Implementation5
6Implementation – cont.
7Applicability & Examples
8Applicability & Examples – cont.
9Applicability & Examples – cont.
10Applicability & Examples – cont.
11Applicability & Examples – cont.
12Applicability & Examples – cont.
13Applicability & Examples – cont.Email Subscriber: 《集中市場》三大法人賣超79億元,法說會績優股力抗國際崩跌SMS Subscriber: 《集中市場》三大法人賣超79億元,法說會績優股力抗國際崩跌RSS Subscriber: 《集中市場》三大法人賣超79億元,法說會績優股力抗國際崩跌----------------------------------------------------Email Subscriber: 台股盤後-鴻家軍登高力抗希臘債信危機 開低拉高力守8000關SMS Subscriber: 台股盤後-鴻家軍登高力抗希臘債信危機 開低拉高力守8000關RSS Subscriber: 台股盤後-鴻家軍登高力抗希臘債信危機 開低拉高力守8000關---------------------------------------------------

Observer Pattern