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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:23:20+00:00 2026-05-20T14:23:20+00:00

I was thinking of a loader class and came up with two different approaches.

  • 0

I was thinking of a loader class and came up with two different approaches.

class Loader{
public:
  Loader(const Path& path);
  File load() const;

private:
  Path path_;
};

vs

class Loader{
public:
  Loader();
  File load(const Path& path) const;
};

With the first approach, I need one Loader per file and the Loader class represents a state. With the second one, I can load different Files with one loader class.
Besides these obvious differences which approach would you choose and why or is there a third maybe superiour way?

  • 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-20T14:23:21+00:00Added an answer on May 20, 2026 at 2:23 pm

    There are other approaches as well.

    If you don’t maintain any state in the Loader class when loading a file, then you can simply write a free function

    File load(const Path& path); //a free function.
    

    Or you can make the function static if you want it to be a member function

    class Loader{
    public:
      static File load(const Path& path);
    };
    
    //usage
    Loader::load(path);
    

    Sometimes such solutions entirely depend on the situation, and sometimes on company/programmer’s personal preferences and taste. There is no one best solution as such!

    You can even choose to write the load function in the File class itself:

    class File {
    public:
      bool load(const Path& path); //non-static, or/and the next one!
      static File load(const Path& path); //static
    };
    

    In this, maybe, you would want to change the name of the function: open() seems better than load().

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

Sidebar

Related Questions

There is a requirement to load a list of items(ArrayList) from two different tables.
Thinking about if we modify the definition of Hamiltonian path as we need to
While thinking about this question and conversing with the participants, the idea came up
I have a Main class loading 2 SWF (loader and viewer, also with document
does any knows how to access .jar file in JS. I have created class
I've implemented a wavefront (OBJ) file loader for my OpenGL app which provides me
Thinking about getting into .net technology project management I've had plenty of experience with
Thinking about a Windows-hosted build process that will periodically drop files to disk to
Thinking in regards to Sliverlight, I would like to know where would be good
Thinking about my other problem , i decided I can't even create a regular

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.