Backstory: I am working on a Wizard Setup project and I've ended up with a very big(a lot of lines of code) Form class. Because my form holds a Wizard control which in turn has lots of pages and each page has input controls that need to be taken into account and saved in the database, the events that fire upon user input have quite a lot of things to do.

Question: Are there any clean code rules specific to Form classes?

I'm trying to figure out if it would make more sense for me to move my event functionaity in a different class and just send my data and controls to that class for processing?

  • 1
    You could use partial classes and split the functionality across multiple files in a way that makes sense. – Broots Waymb Oct 7 '15 at 14:06

Your goal should be to push as much of your program logic out of the form class and into other classes as possible. This decouples the content of the form from the actual program functionality, and makes everything easier to test.

Consider following a software pattern specifically designed for this purpose: Model-View-Presenter or MVP. The "Build your own CAB" article by Jeremy Miller describes this process in detail. There are also MVP examples on Codeplex like Claymore MVP that you can try.

Further Reading
Build your own CAB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.