MVC vs MVP vs MVVM

M-V-C

Model–view–controller is both an architectural pattern and a design pattern, depending on where it is used. we can essentially break dow it into there major components from its analogy

  • M - Model - your business entities / data
  • V - View - your UI
  • C - Controller - Implemetation of your business use case.

Controller will be ignorant about View, so that that a View can switch Controllers as well as single controller can be used by multiple Views . One of the disadvantages of MVC is that it’s difficult to unit test. Controller manipulates the data but how about asserting those changes from a view perspective. For instance on click of a button you raise an event to controller, and controller modifies the value in model. This value modification changes the font size / color in View.


M-V-P


  • M - Model - your business entities / data
  • V - View - your UI
  • P- Presenter

Over here we replace Controller with Presenter (one which presents the changes done in model back to view). The main difference between both is that Presenter refers back to the view while Controller doesn’t. Normal pattern found here is to create an interfaceof the View (in terms of properties / events) & Presenter refers to it. Presenter here hence takes the responsibility of not only manipulating model but also updating the view.

M-V-VM


  • M - Model - your business entities / data
  • V - View - your UI
  • VM- View Model

Model–View-ViewModel talks of creating a new model (in addition to your domain model). This model normally adds additonal properties from the prespective of View . For instance if View had a property IsChecked and Presenter was setting in classic MVP, in MVVM Presenter will have that IsChecked Property which View will sync up with . So now a Presenter becomes more like a combo of – View Properties & Model properties which would be synchronized with View. So why not rename Presenter to ViewModel? Do that and you get MVVM. MVVM is attractive for platforms which support bi-directional binding with less effort.

Create MSI from Command Line

Before continuing, the limitation of this method is that you need visual studio installed in the machine where you want to build the MSI. So now that i put the gotcha up front lets proceed. all u got to do is
devenv MySetUpproject.vdproj /rebuild

and u get a new setup.msi and setup.exe.

what i'm currently doing is using a batch file to do this

this is my complete batch file


D:
cd D:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\
devenv %1\Service.sln /project "Setup\Setup.vdproj" /projectconfig Release /rebuild


I'm setting the path to my devenv folder and then calling the devenv exe from command line using a parameter sent to the batch file (%1). :)..since we are giving a switch devenv wont open and build the project from the command line itself.

Tree View -Data Binding - n level

Thought I will start with the control that gave me many sleepless nights, WPF Tree view. When I started off with WPF I needed to show a recursive object in a tree view and frankly had night mares doing so but in the end it turned out pretty simple. So let’s consider a class as shown below
public class Person
{
string _Name;
int _Age;
List _Children;
public Person()
{
_Children = new List();
}
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
}
}
public int Age
{
get
{
return _Age;
}
set
{
_Age = value;
}
}
public List Children
{
get
{
return _Children;
}
}
}

So as u can see the no: of levels can be determined at runtime only.Now what we will do is let WPF do all the hard work and find out how many levels there are while we sit back and enjoy the show.To do this we use the tree view with the template shown below –


<TreeView Name="trVwPerson">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType = "{x:Type obj:Person}"
ItemsSource = "{Binding Path=Children}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock Width="10"/>
<TextBlock Text="{Binding Path=Age}"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>


Here we are using a Hierarchial Data template and sets it’s data type
as the class we have declared earlier, so when we set the item source of the tree , it will automatically pick this template for an object of type Person and apply it as the item template.
To bind the item source I’ just create a junk list of the said class and set it to the item source of the tree view.
List Souce = new List();
Person P1 =
new Person()
{
Name = "GrandFather",
Age = 90
};
Person P11 = new Person()
{
Name = "Father1",
Age = 60
};
Person P111 = new Person()
{
Name = "Child1",
Age = 30
};
P11.Children.Add(P111);
Person P12 = new Person()
{
Name = "Father2",
Age = 60
};

P1.Children.Add(P11);
P1.Children.Add(P12);

Person P2 =
new Person()
{
Name = "GrandFather2",
Age = 91
};
Person P3 =
new Person()
{
Name = "GrandFather3",
Age = 92
};
Souce.Add(P1);
Souce.Add(P2);
Souce.Add(P3);
trVwPerson.ItemsSource = Souce;
and there u have a hierarchial tree with n number of levels.