frank_ulbricht wrote:
Hi folks,
I'm a Java programmer and now I have to use C# for a new large
project. The language is the best I've ever seen. In some points it
goes far beyond Java. I like that.
But then there was a great dissappointments about WinForms. Compared
with Java/Swing (skip the performance, I mean the development) it is
very poor at first sight. It reminds me when I startet in 1995 with
Delphi (guess a guy named Heilsberg is the reason :wink: ). Is it
true there is no MVC concept in WinForms? Is there any way (or third
party lib) to use a MVC pattern with WinForms?
Sure you can (and should) do MVC in Windows Forms. Unfortunately, there's
little to no documentation on this topic, and all (Windows Forms) books I
know fail in this area as well. So here's my recipe for using MVC in Windows
Forms (just a whirlwind tour, not a methodology ;->):
1. Write the application model. Do not tie it in any way to the UI layer by
having dependencies to it. Test the heck out of it using NUnit, csUnit, etc.
2. Expose all relevant properties of the model and add events for each
property change that needs to be communicated to the UI layer. This can be
done at any level of granularity, from a single ModelChanged event to one
event per property.
3. Design the UI.
4. Implement the UI's event handlers so they update the model's properties
as required.
5. Implement model event handlers in the UI classes that update the UI on
model updates.
As you might realize, .NET events and delegates actually make it easier (or
nicer) to implement MVC. What you're still missing are the default models
that come with Swing for each type of control, but I doubt their value
anyway, because having a model per control is hardly desirable -- the model
should reflect the problem domain in terms of the domain.
Note that there's also a MVC framework for Windows Forms and ASP.NET: The
User Interface Process Block at
http://msdn.microsoft.com/library/de...html/uipab.asp.
Cheers,
--
Joerg Jooss
jo*********@gmx.net