views:

93

answers:

5

Is there anything that helps provide structure for good separation of concerns in a thick client or smart client app like asp.net mvc does for web?

+1  A: 

While not WinForms the WPF Toolkit from Codeplex has a model-view application template for Visual Studio.

This MSDN article on patterns also has some downloadable content that might be useful.

ChrisF
he wants a framework for windows form
Benny
@benny - well to my understanding, WPF runs in much the same light as windows forms, a thick or smart client. So this answer is helpful.
Maslow
+3  A: 

For WinForms, I don't know any such framework (although it must probably exist). But if you're willing to switch to WPF, the MVVM pattern is exactly what you need, and there are many frameworks to make your life easier with this pattern.

You can find a list of MVVM frameworks on Jeremy Alles's blog, and even a comparison matrix

Thomas Levesque
A: 

It might be worth looking at the Smart Client Software Factory. Much of the focus was on composite applications but it does use views and I think the MVP pattern.

For WPF or Silverlight have a look at Prism.

jbloomer
SCSF *depends* on CAB, no?
johnny g
Yes."The Smart Client Software Factory includes the source code and signed assemblies for the Composite UI Application Block. The source code matches the code in the Composite UI Application Block – December 2005 release."
jbloomer
+2  A: 

MVC is just a pattern, and may be implemented quite easily without any framework whatsoever. It mostly dictates Separation of Concern [SoC] as concerns Gui and business functionality. I would also recommend you look up Model-View-Presenter [MVP] and Model-View-ViewModel [MVVM] - slight variations of MVC. MVVM is more prevalent than strict MVC.

Ahem, that aside, there are several enablers of MVC, such as Inversion of Control [IoC] and Dependency Injection [DI]. These patterns facilitate the creation of, and automate the "wiring" of your MVC components so that they may communicate with each other. In this respect, you may wish to take a look at Microsoft's ObjectBuilder [if targetting .Net 2.0], or roll with the much lighter-weight Unity container if you would like something more recent. I personally prefer Castle Windsor container for all of my IoC work, but Unity is maturing and I may switch over soon.

Of course you could also look at the frameworks these components are part of, namely Composite Application Block [CAB] or Prism respectively, but I wouldn't advise it. They offer some nifty solutions [you can emulate "Commands" in WinForms with CAB's EventBroker] but unless you have specific requirements, it's a lot of extra baggage imo.

If you understand the pattern [MVC], then a template is largely unnecessary.


If you are wondering how the bits come together, a quick MVC crash course:

// this is the controller. manages business logic, handles
// Gui inputs
public class Controller
{

    // constructor
    public Controller (View view, Model model) 
    {

        // nothing magical about wiring things up
        // obtain reference through ctor here, and
        // hook up events, or provide bindings

        // attach event handler - obviously make sure
        // signatures match etc, i'm winging this whole thing
        view.ButtonSubmit.Click += Submit;

        // understand this will set the value of view's
        // text once, here on instantiation. the problem
        // with WinForms is databinding, you will have to
        // roll your own. to provide proper databinding
        // Model class must expose events when they change
        // and then Controller or View must listen to event
        // and bind new value to View
        view.TextBox.Text = model.Count;

    }

    // Submit button clicked!
    public void Submit () { ... }

}

// this is the model. contains all data relevant
// to Gui component
public class Model
{
    // a count of stuff
    public int Count { get; set; }
}

// this is the view. simple WinForms object,
// contains buttons, white fluffy clouds, and other
// good stuff
public class View : Control
{
    public TextBox TextBoxCount;
    public Button ButtonSubmit;
}

public static class Program
{
    static void Main ()
    {
        // you can do this explicitly like below, or implicitly
        // if you configure and use an IoC container.
        View view = new View ();
        Model model = new Model ();
        Controller controller = new Controller (view, model);
    }
}

The main disadvantage to MVC + WinForms, is above in the Controller. The Controller is referencing WinForms objects directly, which makes most scenarios difficult to unit test. What you would like is an abstraction from Gui elements and the events they throw. Also, you don't want to do the repetitive data binding task I allude to by inline comment. WPF adddresses these by introducing Commands and databinding.

johnny g
I'm looking for things that will help me see where the different parts fit. asp.net MVC was very helpful in providing a template of how to do separation of concerns for a web project, so although I've got ideas, and feel familiar with IoC and DI, working out a good architecture for forms would be simpler with a framework that has been fleshed out. I will look into WPF, I have avoided it on the fear that's mainly for someone better at design.
Maslow
Hm, I learned MVC [followed by MVP, then MVVM] through CAB + WinForms. My experience, one heck of a PITA. Massive learning curve, but I had help from some very knowledgeable friends. If you have options atm, I would strongly advise looking at WPF [apart from MVC], and then look around at what people are doing there. If given a choice, I would work exclusively with WPF and MVVM.
johnny g
a good example, esp. for off the cuff. Beware if the controller does anything to change the GUI on a secondary thread though...
Steven A. Lowe
+1  A: 

This SO link has some useful WPF frameworks discussed, some from MS.

kenny
+1 very interesting link
Maslow