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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:33:46+00:00 2026-06-13T18:33:46+00:00

I was wondering whether it was a good practice to define algorithm parameter settings

  • 0

I was wondering whether it was a good practice to define algorithm parameter settings as an independent class. I illustrate my question with the following codes:

using namespace std;

class Parameters
{
public:
    Parameters():a_para_(0),b_para_(0) {};
    ~Parameters() {};
    Parameters(const Parameters &para)
    {
        a_para_ = para.a_para_;
        b_para_ = para.b_para_;
    }
    void set_a_parameter(int a)
    {
        a_para_ = a;
    }
    void set_b_parameter(int b)
    {
        b_para_ = b;
    }
private:
    int a_para_;
    int b_para_;
};

class Algorithm
{
public:
    Algorithm() {};
    ~Algorithm() {};
    void set(const Parameters &para)
    {
        para_ = para;
    }
    void run()
    {
    }
private:
    Parameters para_;
};


int main()
{
    Parameters para;
    para.set_a_parameter(3);
    para.set_b_parameter(4);
    Algorithm fun;
    fun.set(para);
    fun.run();

    return 0;
}

The philosophy behind is that the parameter setting and algorithm implementation can be separated. I discussed this design strategy with an experienced programmer, and it seems that he prefer that the parameter setting and the algorithm should be mixed together as one class. I am therefore writing here for your advice: which one is better? Thanks!

  • 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-06-13T18:33:47+00:00Added an answer on June 13, 2026 at 6:33 pm

    Your question is very general, and there’s no general answer. It depends on the situation.

    Often times you want to be able to decide at compile time the parameters of your algorithm (for instance, the size of a given buffer, or the dimension of a matrix, or the arity of a tree nodes). Usually these parameters don’t change for the lifetime of your algorithm “instance”, so to speak. In this context, it is usually good practice to turn your algorithm class into a template, and make these parameters the template parameters.

    If the parameters must change during the algorithm lifetime, but their implementation are trivial, there’s no need to externalize them. If they are non trivial, and their implementation details may change the algorithm performance (ex: a matrix implementation based on arrays for dense matrices, or on linked lists for sparse ones), then I suppose that you could externalize that parameter.

    I think you should ask a more specific question if you want to get a better answer.

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

Sidebar

Related Questions

I'm following the Fail Fast principal. I'm wondering whether it's good practice to have
I wondering whether anyone has any good ideas on optimizing the following code. I
I am curious whether it is good practice to make a new main JPanel
Question #1: Is declaring a variable inside a loop a good practice or bad
I am just wondering whether there is a good login window open source that
I've been wondering whether transparent implicit conversions are really such a good idea and
I've been wondering whether transparent implicit conversions are really such a good idea and
I was wondering whether the use of a decorator pattern is good in case
I was wondering whether anybody out there is actively using Rhapsody TestConductor ? Or
I was wondering whether there're recommendable sites, that host collections of good and useful

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.