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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:50:47+00:00 2026-05-26T05:50:47+00:00

I am coding a directory parser utility, which scans different directories for different type

  • 0

I am coding a directory parser utility, which scans different directories for different type of files.

Now a straightforward implementation urges me to do the following.
Have a list of directories to parse, loop over them and pass it to a method that actually does the file I/O and other logic and returns the result.

List<Dir> dirList;
//loop over the list and call parseDirecotry()
parseDirectory(Dir dirToParse){
 //do file io
 if (filename.matches("pattern"){
 //proceed)
 }
}

Each directory that’s scanned requires me to filter out certain files. So now
for certails dir the match pattern will vary, now either I could keep adding the match pattern based on the type of directory in if else logic.
Or
I could take the pattern out make of it a part of the Dir object, make it abstract, have specific directory implementations hold the specific match pattern.

This way I don’t have to touch the parseDirectory method every time I have a new directory to scan.

Question is: is there some design pattern that I could possible leverage here? What are you views about the above program to interface way and do you think if it would make sense to move the parseDirectory() method up to the abstract directory class as well?

  • 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-26T05:50:47+00:00Added an answer on May 26, 2026 at 5:50 am

    OK I will propose my solution

    1) Create an interface called IFileProcessor having method processFile
    2) Create singleton classes specific to document types implementing IFileProcessor. So the classes will be DocFileProcessor, XLSFileProcessor etc and each class will have its own specific implementation of processFile API.
    3)Create a factory class say FileProcessorFactory. It should have an API called IFileProcessor getFileProcessor(String fileTypeExtension) . This API will take file extension as input and return the DocFileProcessor, XLSFileProcessor etc for input doc, xls etc.
    4) In your loop call getFileProcessor of FileProcessorFactory giving it input. Now call processFile on returned instance.

    Having this design decouples the logic of if-else to Factor allowing you logic to remain independent of the file types.

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

Sidebar

Related Questions

I am coding a class that compares the files of two directories via comparing
I'm coding some c# against Active Directory and have tried endlessly to get this
Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding
I have a directory with all my coding projects. I want to upload (correct
I'm coding a resource site around a fairly large directory database, and I'd like
I have a list of files in a directory. I have to process only
I'm python beginner: how can I iterate over csv files in one directory and
I'm coding some scripts which execute git-rebase and need to identify when a conflict
I have a script called 'sess-start.php' which lies in an /include directory within my
I have a large number of files in a ClearCase directory structure, and 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.