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 3427160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:48:10+00:00 2026-05-18T06:48:10+00:00

I’m working through a CSV importing approach that I want to teach to other

  • 0

I’m working through a CSV importing approach that I want to teach to other people I work with where I’m concerned with the following:

  1. Validating each record before attempting to process (e.g. persist).
  2. Failure on any record prevents processing.
  3. Providing status during validation and processing.

What I’m looking for is thoughts on if the following classes and usage example appear clear enough to meet the intent described.

There are three classes.

Importer: manages the overall algorithm, keeps track of validation errors, provides the algorithm to convert each CSV line to data construct that can be validated or processed.

Importer(CSVFile)
getProcessor(): Processor
getValidator(): Validator
getErrors(): array
isOKToProcess(): boolean
lineToData(String data): Object

Validator: validates entire file and each row to ensure it’s OK to process

close(): void
currentRow(): int
hasNext(): boolean
doNext(): void

Processor: persists each row

close(): void
currentRow(): int
hasNext(): boolean
doNext(): void

As you can see the last two roughly adhere to a Java style iterator. The client interaction is thus (psuedocode – assume output is flushed immediately to the buffer):

importer = new Importer("/path/to/file.csv");
validator = importer.getValidator();
writeOutput("validating<br/>");
while (validator.hasNext()) {
  validator.doNext();  
  writeOutput(validator.currentRow() & "<br/>");
}
validator.close();
if (!importer.isOKToProcess()) {
  writeOutput("errors<br/>");
  writeOutput(importer.getErrors());
  return; // short circuit
}
processor = importer.getProcessor();
writeOutput("processing<br/>");
while(processor.hasNext()) {
  processor.doNext();
  writeOutput(processor.currentRow()  & "<br/>");
}
processor.close();

Some specific questions, but please feel free to critique otherwise:

  1. Make sense to use two separate classes (in practice probably inner) for validating and processing? Or perhaps move everything into one Importer class?
  2. getErrors() in Validator instead, because that’s where the errors are raised?
  3. currentRow() on Importer instead of Validator and Processor because it’s really the current row of the overall import?
  • 1 1 Answer
  • 0 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-18T06:48:11+00:00Added an answer on May 18, 2026 at 6:48 am

    From an OO perspective I think it is right to keep the classes seperate. I do not think it is even necessary to make the Validator an inner class. Think of it from this angle. If you implement this generically (maybe so that one day you can pass in a grammer or some kind of specification which tells the Validator how to validate), you can use it to validate multiple types of CSV files. In that case, you would not want it contained in an outer Importer class. Otherwise you would have to write an Importer / Validator combination each time.

    An Importer is an importer, a Validator is a validator.

    I would definitely move the getErrors() method into the Validator. Otherwise its like someone else taking credit for the work you have done. Since the Validator is doing the validation, let it tell the world of the errors it found. Don’t give the glory to the Importer, it has not done anything yet.

    Your third point does not make quite sense. Both the Validator and the Importer has the currentRow() method. This seems correct. They are functianally different and both need to keep track of progress. One change you might be able to make is to give the Validator have a getTotalNumRows() method. This way, once the file is validated, the Importer can ask the Validator how many rows it read during validation. This will enable the Importer to display progress better, ie. as a percentage rather than only showing on which line it is.

    Other than that, I think your design is good.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.