Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 317251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:27:31+00:00 2026-05-12T08:27:31+00:00

Simple question for all you pragmatic object-oriented fellas. I have read many times to

  • 0

Simple question for all you pragmatic object-oriented fellas.
I have read many times to avoid classes like “Processor”, and “xxxxHandler” in order to agree to OO standards: and I believe it’s a good measure for understandability of the system code.

Let’s assume we have a software that scans some file structure, let’s say a bunch of specific CSV files. Let’s say we have an independent module called CsvParser.

class CsvParser {
    public string GetToken(int position) { .. }
    public bool ReadLine() { .. }
}

class MyCsvFile {
    public string FullPath { get; }

    public void Scan() {
        CsvParser csvp(FullPath);
        while (csvp.ReadLine())
        {
            /* Parse the file that this class represents */
        }
    }
}

This will save having a “FileScanner” class, which is a -Processor- type class. Something that will collect say, a bunch of files from a directory, and scan each.

class MyFileScan {
    public string[] Files { get; set; }

    public void GetFiles() { this.Files = Directory.GetFiles(..); }

    public void ScanFiles() {
        foreach (string thisFilePath in Files)
        {
           CsvParser csvp(thisFilePath);
           /* ... */
        }
    }
}

The OO approach dictates having the MyCsvFile class, and then a method representing the operation on the object.

Any thoughts? What do you programmers think.

  • 1 1 Answer
  • 5 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:27:32+00:00Added an answer on May 12, 2026 at 8:27 am

    I think what you’re describing is that objects should take care of operations that only require themselves, which is in general a good rule to follow. There’s nothing wrong with a “processor” class, as long as it “processes” a few different (but related) things. But if you have a class that only processes one thing (like a CSV parser only parses CSVs) then really there’s no reason for the thing that the processor processes not to do the processing on itself.

    However, there is a common reason for breaking this rule: usually you don’t want to do things you don’t have to do. For example, with your CSV class, if all you want is to find the row in the CSV where the first cell is “Bob” and get the third column in that row (which is, say, Bob’s birth date) then you don’t want to read in the entire file, parse it, and then search through the nice data structure you just created: it’s inefficient, especially if your CSV has 100K lines and Bob’s entry was on line 5.

    You could redesign your CSV class to do small-scale operations on CSV’s, like skipping to the next line and getting the first cell. But now you’re implementing methods that you wouldn’t really speak of a CSV having. CSV’s don’t read lines, they store them. They don’t find cells, they just have them. Furthermore, if you want to do a large-scale operation such as reading in the entire CSV and sorting the lines by the first cell, you’ll wish you had your old way of reading in the entire file, parsing it, and going over the whole data structure you created. You could do both in the same class, but now your class is really two classes for two different purposes. Your class has lost cohesion and any instance of the class you create is going to have twice as much baggage, while you’re only likely to use half of it.

    In this case, it makes sense to have a high-level abstraction of the CSV (for the large-scale operations) and a “processor” class for low-level operations. (The following is written in Java since I know that better than I know C#):

    public class CSV
    {
        final private String filename;
        private String[][] data;
        private boolean loaded;
    
        public CSV(String filename) { ... }
    
        public boolean isLoaded() { ... }
        public void load() { ... }
        public void saveChanges() { ... }
        public void insertRowAt(int rowIndex, String[] row) { ... }
        public void sortRowsByColumn(int columnIndex) { ... }
    
        ...
    }
    
    public class CSVReader
    {
        /*
         * This kind of thing is reasonably implemented as a subclassable singleton
         * because it doesn't hold state but you might want to subclass it, perhaps with
         * a processor class for another tabular file format.
         */
        protected CSVReader();
        protected static class SingletonHolder
        {
            final public static CSVReader instance = new CSVReader();
        }
    
        public static CSVReader getInstance()
        {
            return SingletonHolder.instance;
        }
    
        public String getCell(String filename, int row, int column) { ... }
        public String searchRelative(String filename,
            String searchValue,
            int searchColumn,
            int returnColumn)
        { ... }
    
        ...
    }
    

    A similar well-known example of this is SAX and DOM. SAX is the low-level, fine-grained access, while DOM is the high-level abstraction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright simple question I have integriters like 5 188 4634 And they all need
Hey all, simple question I'm sure, but I would like to have the body
I know it may be simple question to all experienced developer.. I have trapped
Hey all. I have a fairly simple question. I am developing a rich iPad
Simple question. I have a panel with 3 components. All of them are have
Morning all, I have a simple question that I could do with some help
Hello all friendly Windows Mobile Developers! I have a simple question: Can I distribute
a simple question for all you SQL gurus: I have the following table structures
I hope I have a simple question for you all, but working with dates
I have a simple question - basically I want to fetch all ActiveRecords of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.