Posts Tagged mvp
Another Thursday, another fun Virtual Brown Bag. JB shared some more Rails/Heroku love today, and how he’s implemented the registration/login feature of http://www.virtualbrownbag.com. The more I hear and see things about Rails/Heroku, the more I like it. I need to find me some time to start messing with those things.
We had a special request from Mark, one of our frequent VBBers: he wanted to see a little example of MVVM, and maybe have a little talk on MVC.
I showed a very simplistic sample of a WPF app, where we started with having most of the code in a code-behind for a window, and then moving the code out into a ViewModel. We’ve covered the core differences between MVC (Model-View-Controller), MVP (Model-View-Presenter), and MVVM (Model-View-ViewModel, or also known as Presentation Model). The idea bein g that they’re all “presentation patterns”, aimed to better structure the code that sits closer to the User Interface.
So why so many different patterns just for that? Well, each one has a slight different structure to cater for the scenario have at hand. In MVP, the Presenter takes care of providing behavior to the View. The View does nothing more than delegating things to the Presenter. This allows the Presenter to be reused independently of the View, and it’s also testable.
In MVVM, the ViewModel gives shape to the data coming from the Model, tailoring it to the View needs. For instance, the Model may have separate properties for Address, City, State, whereas the View calls for just a single property representing the Full Address; the ViewModel will handle just massaging of the data. ViewModels fit in nicely with WPF/Silverlight due to their data binding features.
In MVC, the Controller is usually the one responsible for executing behavior, and in web applications the Controller is usually the point of entry for the user to execute operations: when the user either enters a URL in the browser directly, or clicks something on the page that sends a request to the server, there’s a Controller intercepts the call and takes the appropriate action.
ViewModels are commonly used in MVC applications as well, but different than in WPF/Silverlight applications, they only provide the “data reshaping” aspect of it.
Even on a MVVM WPF/Silverlight application you may find “Controllers”, usually helping out with the way the application flows through menus and screens.
MVP is usually the best bet for WinForms and WebForms applications. So why not use MVVM in a WinForms application? Because MVVM leverages the WPF/Silverlight data binding capabilities, which in WinForms aren’t that great.
As with all design patterns, there isn’t one presentation pattern that’s the silver bullet to all applications. Depending on context, requirements, etc., a single application may mix and match these patterns: have a Login screen implemented using MVP, whereas an order placement screen may be implemented using MVVP, whereas a more complex composite screen may be using MVVM with a Controller added to handle the flow between the different parts of the screen.
This post isn’t supposed to be nothing more than a brain dump as to what we’ve discussed at the Virtual Brown Bag this week. Please make sure to take the time and go do some research and experimentation on your own.
- The 1st one: I was full-throtle on helping the Visual FoxPro community in Brazil, mostly because I knew many developers were having a real hard time using VFP due to the lack of material in Portuguese. I then got involved with writing articles, putting together a magazine, doing presentations, actively participating on forums, etc. At the time, Brazil only had 5 or 6 MVPs, and I was the first one to be awarded for Visual FoxPro. That was a BIG honor for me.
- The 2nd one: that one was special because the nomination didn’t come from the MS Brazil; it actually came from Redmond. That meant that the folks at that Fox Team had heard about me, and were noticing my efforts in helping the community.
- The 3rd one: at first, I got nominated again by the Fox Team at Redmond. But at that time I wasn’t doing a lot of work in VFP anymore; I was doing a lot more with .NET, even though I was still writing articles and doing presentations for the VFP developers, mostly helping them learning .NET and leveraging their knowledge acquired over the years working with VFP. When attending the MVP summit at Redmond that year, I’ve asked if I could switch from being a VFP MVP to a C# MVP, and they were cool about it. So that was good because it represented better what I was working with those days.
- The 4th one: I wasn’t sure I was going to be awarded; I wasn’t an exclusive VFP developer anymore, and wasn’t well-known on the .NET community. Regardless, the MVP reviewers kept an eye on the articles and presentations I was doing, and decided I should be awarded again. I was really happy with that.
- The 5th one: with the huge number of developers on the .NET community, and the big number of existent .NET MVPs, it’s getting more and more special to be awarded along with so many bright minds well-known "guru-like" MVPs out there. I’m really happy I can still be part of the group.
That’s it for now.
This is good news: last night I’ve received an email from Microsoft saying I’ve received the Microsoft MVP Award one more time. This is the 4th year in a row I receive the award, and I’m pretty happy to know that my work with the software developers’ community is still relevant.