需求
“Create an observer-pattern UML class diagram where Stock implements Subject and Investor and PriceDisplay implement Observer for stock price updates.”
接著試試Add a NewsDisplay observer.Add a volume field to Stock.
這張圖裡有什麼
看懂背後的決策。
01
Modeled Subject and Observer as interfaces for extensibility.
02
Used aggregation to show the subject holds a collection of observers.
03
Added directed associations from observers back to the subject for state retrieval.
When designing systems requiring one-to-many dependencies and automatic notifications, such as event handling, monitoring, or publish-subscribe mechanisms.