问题
I understand how the Observer pattern works, but why is it that the Observer pattern reduces coupling between UI and business logic components in software design?
回答1:
The Observer pattern reduces coupling among its participants because it introduces an abstract type, Observer, between the Subject and its Observers.
Imagine a Model (the Subject in the Gang of Four/Wikipedia description, and the home of business logic) and a View (an Observer). Without Observer, the Model would need to call a method on the View whenever it changed. The Model would know the concrete class of View and be coupled to it, and to whatever UI-specific framework the View was a part of.
With Observer, the Model only knows about the type (abstract class or interface) Observer, so it is not coupled to the concrete View.
来源:https://stackoverflow.com/questions/36868384/how-does-the-observer-pattern-reduce-coupling