Question

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.

Was it helpful?

Solution

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:

  • Your ViewModel (MVVM) has Properties which you want to display / update in your XAML-VIEW (MVVM). Anytime you set (or update) a Property value (in your ViewModel) you trigger something like ()=> PropertyChanged("PropertyName);
  • The Observer is now in your MVVM Framework (Or Base Class of ViewModel) this component observes these changes and manages the update with the VIEW.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top