1

I have used WPF for an Enterprise solution (hundreds views heavily used Data inputs and validation) in MVP pattern (it was a clean solution usually small amount of code behind forms and main code was in pretension layer which we called it user interface process or UIP layer )

For the next small projects I used WPF with MVVM. generally some ideas of MVVM looks nice like commands and bindings especially the concept of ViewModel (having a special version of Model dedicated for View)

But I did not like so much the concept of Messaging and event aggregator I usually try to minimize usage of this patterns (for example between ViewModels I use ordinary Object oriented function call or from a View to ViewModel (I have ViewModel in my View so I use them to call ViewModel from View) but for a call from a view model to view I use messaging. though sometimes in place of sending messages (from ViewModel to View) I send an Interface of view to its ViewModel and use that interface to call a function in a view. Any body can tell me is this practice an anti pattern and why it is bad?

1

Seems fine to me. ViewModel defines an interface it requires View to implement. But you should only use this when you can't use data binding properly. Eg. you want view to do some action that is not tied to data the view presents.

Why I think this is fine is: The major point of MVVM (or MVP for that matter) is to remove direct dependency between View and ViewModel in either direction. In MVVM, this is mostly achieved by heavy use of reflection in data binding. But sometimes that is not enough, because you cannot easily invoke some action on View from ViewModel. To do that, you create abstraction that represents this action so ViewModel can call this abstracion and View realizes this abstraction. This way, there is still no direct dependence between View and ViewModel, but you can overcome the limitation of data binding.

  • This answer is a little vague. Think you could shore it up a bit? – Robert Harvey Apr 10 '14 at 18:14
  • Exactly it was the main reason I use this interface passing I need to call a blocking function in my View from its ViewModel and it is not event possible with messaging or event aggregator system. – Mojtaba Apr 11 '14 at 10:26
  • @Mojtaba_Sarooghi What do you mean by blocking function? – Euphoric Apr 11 '14 at 10:54
  • @Euphoric A function which needs the return value not like message send and forget maybe blocking was not a right word for it. A function which do a UI specific calculation and returns the result. – Mojtaba Apr 11 '14 at 11:17
  • Apart from the above scenario which is not easily affordable with messages(returning the result from message handler stakoverflow related question I generally feel heavily usage of messaging cause less readability in source code meaning the flow of application is not easily understandable. – Mojtaba Apr 11 '14 at 11:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.