Question about methods and classes
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Question about methods and classes

  1. #1
    Join Date
    Nov 2012
    Posts
    12

    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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,440

    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).

  3. #3
    Join Date
    Oct 2012
    Posts
    18

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center