views:

270

answers:

1

In general, I prefer to be verbose with .NET class and instance names, but some times (to quote Mike Woodhouse):

Over-verbosity tends to conceal syntax, and syntax is important.

The first place I felt like I really strayed into the over-verbosity regime is upon implementing the Model-View-ViewModel (MVVM) pattern in Silverlight and WPF apps.

For example, I start with an EnumerableRange model object:

public class EnumerableRange<T> : IEnumerable<T>
{ 
    public T Start{ get; set; }
    public T Stop{ get; set; }
    public long Count{ get; set; }
    ...
}

Then, I want to create a control that will allow me to surface this class for user input. Thus, I create a pair of view-related classes:

  1. an EnumerableRangeControlView UserControl (in XAML), and
  2. a POCO EnumerableRangeControlViewModel

Now, I use this pair in the parent View and ViewModel, respectively. With MVVM the view instance doesn't need a name, but my ViewModel instance is now named something like:

IndependentVariableEnumerableRangeControlViewModel.

Things are starting to get out of hand! What would you do?

+1  A: 

I propose the following:

  1. Drop the word "Control" from View/ViewModel classes and instance names altogether. "View" and "ViewModel" clearly state the class purposes.

  2. (Optional) Consistently adopt a convention to post-fix ViewModel instances with "VM".

In the example above, the instance name

IndependentVariableEnumerableRangeControlViewModel

becomes a much more readable

IndependentVariableEnumberableRangeVM
David Cuccia
We adopted something similar. In addition, I have used the idea of just dropping the ViewModel/VM suffix altogether. You can use namespaces to sort out ViewModel.Customer from Model.Customer. This seems like a really bad idea until you remember that your View can only see the ViewModel, so it won't get confused, and the Model can't see anything. In your ViewModel, just don't put the using Model at the top of your code, and you'll always have to refer to it as Model.Customer.
Scott Whitlock