I am looking for a way to design a C# application. I understand 3-tier model, but idk how to apply this in a good C# design.
I have looked some asp.net mvc tutorials, but I am looking for a windows-form based tutorial.
is there any bo开发者_开发百科ok or website to learn a way to implement this?
I believe that traditional MVC is overkill for WinForms. The form is the view, and there's seldom a need for a separate controller. The model is just a class (usually implementing INotifyPropertyChanged). You can use data binding to notify the view that the model has changed.
The important point is to minimize code under buttons. If it's form code, it should either (a) be UI-specific or (b) be delegating calls to the model. Any business logic should be in the model or in classes on which the model depends.
Avoid making the model a God Object. It can delegate internally to other classes.
EDIT: You may want to consider moving the bound data out into a separate object owned by the model. I'd call this Presentation Model, but I don't want to put words in Fowler's mouth.
EDIT2: Important - the model must have NO KNOWLEDGE of the view and NO UI code (such as dialogs).
the first you should know is that design patterns are not one-size-fits-all and therefore there is no such thing as a "Way to implement a design pattern".
If you only mean the 3 tier model then MVC is good choice because it clearly separates each layer from the other, for Windows forms development look for tutorials on Entity Framework (or just LINQ) which, along the classes that handle the logic of the application, becomes your model layer, all the forms, along the classes used to present the data, are your views and, or course, the user controllers are well... that, your controller.
I recommend you take a look at DoFactory website which has a great coverage on many design patterns.
Also I should point out that you may not find an implementation in doFactory, that's just a reference for a bunch of design patterns. JIC.
Hi if you are using Win Forms I recommend you to go for MVP pattern. There one more pattern MVVM (which is mostly used for WPF and Silverlight) but I dont know whether it apply for Win Forms.
精彩评论