form or seperate class code

All topics about coding, designing, etc. goes in here.
Post Reply
geraldhum
Registered User
Posts: 199
Joined: 13 Feb 2009, 12:59

form or seperate class code

Post 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
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: form or seperate class code

Post by rustypup »

are you kludging or using an actual design methodology?..

OOAD coupled with
MVC

what language?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
GDI_Lord
Forum Administrator
Posts: 2663
Joined: 05 Sep 2005, 02:00

Re: form or seperate class code

Post by GDI_Lord »

Am I correct in guessing WinForms in VB.NET or C# geraldhum?
Important Thread: Yours in Christ's service,
geraldhum
Registered User
Posts: 199
Joined: 13 Feb 2009, 12:59

Re: form or seperate class code

Post by geraldhum »

Hi Guys, I'm sorry I thought I put my coding language but I am using Winforms and c#
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: form or seperate class code

Post 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...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Post Reply