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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:27:56+00:00 2026-05-13T09:27:56+00:00

Let’s say you want to construct an Iterator that spits out File objects. What

  • 0

Let’s say you want to construct an Iterator that spits out File objects. What type of data do you usually provide to the constructor of such an Iterator?

  • an array of pre-constructed File objects, or
  • simply raw data (multidimensional array for instance), and let the Iterator create File objects on the fly when Iterated through?

Edit:
Although my question was actually ment to be as general a possible, it seems my example is a bit to broad to tackle general, so I’ll elaborate a bit more. The File objects I’m talking about are actually file references from a database. See these two tables:

folder
| id | folderId | name             |
------------------------------------
|  1 |     null | downloads        |

file
| id | folderId | name             |
------------------------------------
|  1 |        1 | instructions.pdf |

They reference actual folders and files on a filesystem.

Now, I created a FileManager object. This will be able to return a listing of folders and files. For instance:

FileManager::listFiles( Folder $folder );

… would return an Iterator of File objects (or, come to think of it, rather FileReference objects) from the database.

So what my question boils down to is:
If the FileManager object constructs the Iterator in listFiles() would you do something like this (pseudo code):

listFiles( Folder $folder )
{
    // let's assume the following returns an multidimensional array of rows
    $filesData = $db->fetch( $sqlForFetchingFilesFromFolder );
    // let the Iterator take care of constructing the FileReference objects with each iteration
    return FileIterator( $filesData );

}

or (pseudo code):

listFiles( Folder $folder )
{
    // let's assume the following returns an multidimensional array of rows
    $filesData = $db->fetch( $sqlForFetchingFilesFromFolder );
    $files = array();
    for each( $filesData as $fileData )
    {
        $files.push ( new FileReference( $fileData ) );
    }
    // provide the Iterator with precomposed FileReference objects
    return FileIterator( $files );

}

Hope this clarifies things a bit.

  • 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-13T09:27:56+00:00Added an answer on May 13, 2026 at 9:27 am

    What is your “File” object meant to be? An open handle to a file, or a representation of a file system path which can be opened in turn?

    It would generally be a bad idea to open all the files at once – after all, part of the point of using an iterator is that you only access one object at a time. Your iterator could yield one open file at a time, and let the caller take responsibility for closing it, although again that might be slightly odd to use.

    Your requirements aren’t clear, to be honest – in my experience, most iterators which yield a series of files use something like Directory.GetFiles(pattern) – you don’t pass them the raw data at all, you pass them something which they can use to find the data for you.

    It’s not obvious what you’re trying to get at – it feels like you’re trying to ask a general question, but you haven’t provided enough information to let us advise you. It’s like asking, “Do I want to use a string or an integer?” without giving any context.

    EDIT: I would probably push all of that logic into FileIterator, personally. Otherwise it’s hard to see what value it’s really providing. In a language like C# or Python you wouldn’t need a separate class in the first place – you’d just use a generator of some description. In that sense this question isn’t language agnostic 🙁

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

Sidebar

Ask A Question

Stats

  • Questions 387k
  • Answers 387k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Difficult to say, and I don't think there is something… May 15, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer I'm not sure what your actual question is supposed to… May 15, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer From MSDN // Create a request using a URL that… May 15, 2026 at 12:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.