Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Code - making it separate 2

Status
Not open for further replies.

golcarlad

Programmer
Nov 23, 2004
232
GB
I would just like to know what your general approach is when you decide its time to make a form for your project.

I understand that its a good idea to keep your form code seperate from the business logic - what is the best way to implement this?

Here is my idea - but not sure if its right:

1) Create a class called Foo, that makes an instance of the form in question.

2) In the form code make an Init(Foo myFoo) method, where you pass in the Foo object.

3) Back in the Foo class you do a Form.show(this) - where you are sending the Foo object into the form.

4) You work with the Foo class to update/operate certain controls etc on the Form - so now you are not sticking business logic code etc in the form class at all, and therefore are maintaining a separatio of concerns.

Is this right?? I would be interested on your thoughts and ideas.

Regards
 
You should look up MVP or MVC patterns. I prefer the MVP pattern (Model View Presenter)

Here is an artical.

To take this a step further. You could also investigate Smart Client Software Factory as a framework for developing Winforms application. It is also the precursor to project code name Acropolis.



The Smart Client Software Factory provides an integrated set of guidance that assists architects and developers in creating composite smart client applications. The software factory includes: QuickStarts, reference implementations, how to's, patterns, and Visual Studio .NET extensions.
 
stsuing is right.

The Model view Controller Pattern is the way to go. The controller class shouldn't know anything about the controls on your form. And your form shouldn't know anything about working with the data except to display it.

In order to change the data, you should really call a method on the controller which modifies the data and notifies all views (forms in your case) of the data change.

This is why I have a problem with MS. Data Adapters - they allow you to update directly from the view which I believe is a bad thing...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top