0

Whats the best way to organize code responsible for Form's content.

In my case, there is a DataGridView and list, next to it, with a few options available (projects, managers, employees, etc...). Choosing any list's element fills DataGrid with proper data from database.

Now, GridFill functions + handling of all add/delete/edit buttons of each list element gives quite a code in the Form's source, which bothers me a bit.

How to split it then to avoid problems in the future? While googling, I've seen some advices to use partial classes, modules or just classes. Moving all functions relating the Projects, Managers, ... , to own separate class sounds like a nice idea but then comes the question how to pass all necessary data to the class functions. Is passing the reference of the whole form a good idea?

svick
  • 236,525
  • 50
  • 385
  • 514
  • 1
    Finding out that your class is getting top-heavy at a late stage is hard to fix and typically requires a rewrite. Bring some level of organization to the code by using the #region directive and splitting code across source files with the *partial class* keyword. Beware of creating windows that are top-heavy to the user as well. An easy-to-use UI tends to automatically produce easy-to-maintain code as well. – Hans Passant Sep 24 '11 at 21:30
  • It is not a late stage, and I'm ready to rewrite everything if necessary. Is it then still a nice practice to use partial classes in "ideal" design or rather I should try to split it into other classes at all cost? – CzujnyJakZuraw Sep 25 '11 at 07:15

1 Answers1

0

If you're using Winforms, take a look at the MVP (Model, View, Presenter) pattern, which helps separate code related to data, business logic and user interface. This question could also help as the answers provide quite a few interesting links on the subject.

Community
  • 1
  • 1
Manu Clementz
  • 1,807
  • 12
  • 19