What pattern to use in this scenario?
We have got many开发者_开发问答 forms(windows app C#) in our application.We have similar steps in most of them - user adds a new object(in a grid),fills values and save.On,save,we validate,and save if everything ok,else show message.Now,adding of object usually means we add a new row with some default values.
Your question is very broad, so I will answer with an equally broad answer:
You should use a pattern such as MVC or MVVM. You probably want to consider throwing in some of the concepts from DDD such as the repository pattern too.
Is this just a data-entry application? Is it really? Reeeaaally??? Are the validation rules very simple and tend to only be things like "is not empty" and "is in range"? Is there not much domain to speak of? Do you not have to integrate with other applications? Are you not really going to interact with any of this data except for reporting purposes?
If the answer to all this is yes then some sort of template pattern might be for you. Base each form on a base class. The base class has a save method. When you save it it can scan the form for all the controls on it, run any of the more obvious validations (less obvious ones can be stored as attributes) and save a database using conventions (or however else you want to do it).
Then again, if it truly is a data-entry application, why even bother to do it in Windows Forms? Slap it together with an Access DB and be done in a tenth of the time.
On the other hand, if you've got an actual domain then your application is not just a bunch of forms is it? The forms are just a way of issuing commands against a domain - and that's the real meat of what you were hired to do. In that case you should go read the big blue book.
So...yeah.
精彩评论