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

  • Home
  • SEARCH
  • 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 4234380
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:20:48+00:00 2026-05-21T02:20:48+00:00

I have a reasonably-sized class that implements several logically-related algorithms (from graph theory). About

  • 0

I have a reasonably-sized class that implements several logically-related algorithms (from graph theory). About 10-15 parameters are required as input to the algorithm. These are not modified by the algorithm, but are used to guide the operation of it. First, I explain two options for implementing this. My question is what is a common way to do so (whether it is or isn’t one of the two options).

I personally don’t like to pass these values as parameters to the function when N is large, especially while I’m still developing the algorithm.

void runAlgorithm(int param1, double param2, ..., bool paramN);

Instead I have a class Algorithm that contains the algorithms, and I have a struct AlgorithmGlobals that contains these parameters. I either pass this struct to:

void runAlgorithm(AlgorithmGlobals const & globals);

Or I add a public AlgorithmGlobals instance to the class:

class Algorithm {
public:
    AlgorithmGlobals globals;
    void runAlgorithm();
}

Then elsewhere I’d use it like this:

int main() {
    Algorithm algorithm;
    algorithm.globals.param1 = 5;
    algorithm.globals.param2 = 7.3;
    ...
    algorithm.globals.paramN = 5;

    algorithm.runAlgorithm();

    return 0;
}

Note that the constructor of AlgorithmGlobals defines good defaults for each of the parameters so only the parameters with non-default values need to be specified.

AlgorithmGlobals are not made private, because they can be freely modified before the runAlgorithm() function is called. There is no need to “protect” them.

  • 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-21T02:20:49+00:00Added an answer on May 21, 2026 at 2:20 am

    This is called the “Parameter object” pattern, and it’s generally a good thing. I don’t like the member version, especially calling it “XGlobals” and implying that it’s shared all over the place. The Parameter Object pattern instead generally involves creating an instance of the Parameter Object and passing it as a parameter to a function call.

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

Sidebar

Related Questions

I have learned from various tutorial that If a client can reasonably be expected
I have a reasonably sized postresql dump (around 270 mb) that I'm importing into
I have inherited a reasonable sized ASP.net solution that has no automated tests. The
I have a reasonably advanced (many patches and subpatches) quartz composition that was created
Scenario: You have a reasonably sized project with some forms, classes, etc. Question: How
We have a requirement to store 500 measurements per second, coming from several devices.
I have a class that converts images and videos to other formats. A number
I have a class that will have a few instances persistent throughout the duration
I've just started my first development job for a reasonably sized company that has
I have an application that writes several billion records into Cassandra and removes duplicates

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.