tags:

views:

33

answers:

1

A few weeks ago, I came across this article in MSDN magazine which talks about MVVM in general. One of the things that stood out to me was the DynamicViewModel class. It addresses the code-duplication problem common to applications using the MVVM pattern.

So I wonder, has anyone else tried using it? What do you think of it? See, as shallow as it may sound, one of the things that turned me off about it is the lack of intellisense when ViewModels rely purely on dynamic property access. Because of this, I usually tend to just go back with "code duplication" and implement a CLR property in my ViewModel instead.

Also, I'm not sure what the performance hit of using this class introduces. Anyone have an idea?

Thanks.

+1  A: 

Your intuition about IntelliSense is deeper than you think.

In practice, the view model is an interface in all but name. By choosing the subset of properties to implement in the view model, you're explicitly defining the interface that the domain object exposes to the view. Making the view model dynamic, at least in this fashion, discards that decision point. It says that anyone who's designing a view gets to decide what properties of the domain model get exposed directly to the user.

I don't know that it's bad to do that, but I do know that it's bad to do that without thinking it through.

It's the implicitness of it all that bugs me the most about this approach. It seems to me that you're likely to want, somewhere, a list of domain properties that it's OK to make user-facing. Implementing the entire view model by hand is a clumsy way of maintaining this list, but it's a way.

Robert Rossney