-
November 16th, 2012, 03:09 PM
#1
Question about methods and classes
Hello!
Ok I'm making something sort of on the fly and I have learned it's not a good way. That said I was wondering something that
is pretty simple but I'm not sure about. That is should I just put all my methods on the same page as my form controls
and what not? or should I make a new class and store them there.
I'm not doing anything mind blowing just some averaging on numbers that I pulled form a file and the like. I have this
block of code, should I make it into a method on a new class page or just make it a method on the page the controls
are on.
Code:
foreach (string s in fileNames)
{
int lineCount = 0;
string line;
string strHold;
double someDoubleVar;
StreamReader file = new StreamReader(s);
while ((line = file.ReadLine()) != null)
{
strHold = line.Replace("\"","");
if (lineCount == 15)
{
holder = strHold.Split(',');
if (Double.TryParse(holder[2], out someDoubleVar)) { elong.Add(someDoubleVar);}
if (Double.TryParse(holder[3], out someDoubleVar)) { breakStr.Add(someDoubleVar); }
if (Double.TryParse(holder[4], out someDoubleVar)) { mod.Add(someDoubleVar); }
break;
}
lineCount++;
}
}
I hope My made some sense
Stephen
-
November 16th, 2012, 04:40 PM
#2
Re: Question about methods and classes
It's generally a good idea to provide a separation between the UI code and the 'worker' code. So by all means, put the code into separate classes.
Also check out MVC or VM-MV design patterns (which are more of a formal way of doing what you are asking about).
-
November 16th, 2012, 08:26 PM
#3
Re: Question about methods and classes
Generally breaking code into functional pieces have to do a) with reusability b) with readability
When you will revisit this code instead of seeing this block of code you'll have a forexample ParseThisStuff( string FileNamePath);
So in a glimpse you will know what it does and also you can reuse it elsewhere.
Personaly, I try to keep the less possible code with the control. Either making a library, so I can just replace the assmbly (and keeping app's assembly small) or if not possible, I'm breaking the control's (partial) class into parts with specific naming.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|