Page 1 of 1

form or seperate class code

Posted: 18 Nov 2013, 10:33
by geraldhum
Hi guys. I am struggling to understand when do I put code in the form class and when do I create a seperate class to insert the code into there. An example would be. I created a program that stores meta data for movies in a xml file using xml serialization. I never created any classes and inserted all the code into the forms class. My question is should I have created the xml serialization into a different class and just called that up from a button click event. My main question is when do I use a seperate class and when do I write the code into my forms class.

Would if of been better if I created a property for the movie so in abuttons event when I save the xml I could just say

movie.year = txtyear.text
Movie.genre = "Comedy"

Thank you

Re: form or seperate class code

Posted: 18 Nov 2013, 12:14
by rustypup
are you kludging or using an actual design methodology?..

OOAD coupled with
MVC

what language?

Re: form or seperate class code

Posted: 18 Nov 2013, 12:26
by GDI_Lord
Am I correct in guessing WinForms in VB.NET or C# geraldhum?

Re: form or seperate class code

Posted: 19 Nov 2013, 07:02
by geraldhum
Hi Guys, I'm sorry I thought I put my coding language but I am using Winforms and c#

Re: form or seperate class code

Posted: 19 Nov 2013, 08:45
by rustypup
if you're creating something to be used once-off or for a very brief instance, then fine... leave the functional code there.

but it's definitely considered poor, unmaintainable, practice for anything else... you don't want the event stack validating and shunting data, you want it as light and responsive as possible.

so, to answer the question, separate class....

read through the MVC link...