Being new to Silverlight, I had a hard time deciding the structure of my code. This mainly has to do with how I will design my UI. And I’m not a UI person.
In my WinForm days, I was used to code using event handlers and I was writing duplicate codes for each event, whether it be button clicks, selection changed, checkboxes, etc. That turned out to be a nightmare and made me somewhat reluctant in maintaining the code because of the complexities. I realized that I have to avoid doing the same thing for this project if I were not to stop half way.
Fortunately, there is a pattern called MVVM (Model View ViewModel) that solves exactly those issues. It allows me to separate my UI (View) concerns from my code structure concerns. Using this pattern, I no longer need to worry about writing event handlers or codes that depend on how I design my UI. Another great thing about this pattern is testability. It allows me to focus on testing early in the development phase without having to design the UI just so I can test each event and mouse click.
And fortunately again, I can refer to a DevForce app that already has these MVVM principles. The app is called BookShelf and is written by Ward Bell.
Obviously, the BookShelf solution contains more advanced MVVM principles and best practices than what I require at this stage of my development so I’m just going to pick and learn the patterns that I need and apply it as best as I understand it.
The attached DevForce Fantasy Soccer solution is still incomplete in terms of a fully working app. But then again, it will always be a work in progress. Here are the things that worth noting:
My next step is to figure out how to design my UI and attempt to integrate it with my ViewModel. Here’s hoping that I’m on the right track.