I getting confuse with concepts MVVM and observer pattern. Is MVVM itself follows the observer pattern. Or they are totally different from each other?
Can anyone please explain me in simple word.
Thanks in advance.
Model-View-ViewModel (MVVM) is a software design pattern that is structured to separate program logic and user interface controls. MVVM is also known as model-view-binder and was created by Microsoft architects Ken Cooper and John Gossman.
The observe() method takes a LifecycleOwner object. This subscribes the Observer object to the LiveData object so that it is notified of changes. You usually attach the Observer object in a UI controller, such as an activity or fragment.
2 The Subject-Observer Pattern in MVC. The relationship between the model and viewport is actually defined by another design pattern. The subject-observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Observer is a behavioral design pattern. It specifies communication between objects: observable and observers. An observable is an object which notifies observers about the changes in its state.
MVVM- and Observable- Patterns are different Patterns and you will find many great examples. Assuming you are implementing a MVVM Phone App, these two patterns work great in combination:
()=> PropertyChanged("PropertyName);
MVVM is basically an UI pattern. It's main purpose is to separate view from logic. This helps to structure applications and make them more testable because it introduces a clear separation of concerns and allows you to develop extensible applications (if done right).
It is a guidline which can also take advantage of other patterns and works very well with the Binding Engine of XAML-Related development technologies.
Since MVVM is an guidance to structure your application code it can surely take advantage of the observer pattern. For example there is an framework out there which is called ReactiveUI http://www.reactiveui.net/ it implements the MVVM pattern with observeable technologies (RX).
As well with the MVVM basics like notifying the view from the view model via NotifiedChangedProperty and ObservableCollections.
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With