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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:06:58+00:00 2026-06-04T01:06:58+00:00

I am faced with the following conundrum: Our software has an abstract base class

  • 0

I am faced with the following conundrum: Our software has an abstract base class for algorithm objects. All these objects have a common execute() method, e.g.:

class Algorithm
{
public:
  // [...]
  virtual void execute() = 0;
  // [...]
};

For each algorithm that we want to implement, we simply inherit from the base class and store all loaded algorithm objects in a central location. So far, so good.

The problem now lies in the parameters of an algorithm. We want to be able to describe for each algorithm the parameters that need to be set (by an external class). To this end, we gave each algorithm a ParameterList object that contains its parameters. I should clarify that for us, a parameter consists of some kind of type (such as int) and a label (such as “Number of iterations).

The problem now begins when we want to connect the ParameterList to some kind of GUI. Obviously, our algorithms should have no “knowledge” of the graphical API (Qt, GTK, etc.) that we are using. Yet, on the same side, we want to be able to describe algorithm paramters semantically, for example by specifying that the algorithm requires a filename. How this filename is then displayed is up to the GUI.

Is there a way to combine this ParameterList with some kind of semantic type knowledge?

I realize that this question sounds very vague. However, I am not permitted to post any non-trivial code examples (for NDA reasons). So, has anyone been faced with a similar problem in the past?

To wrap it up: We want our objects to describe the parameters they require to a GUI, without knowing the exact details of the GUI.

  • 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-04T01:07:00+00:00Added an answer on June 4, 2026 at 1:07 am

    One option here might be to use the visitor pattern. You can create a base class like this:

    class Parameter {
    public:
        virtual ~Parameter() {} // Polymorphic classes need virtual dtors.
    
        virtual void accept(ParameterVisitor& v) = 0;
    };
    

    You could define subclasses like these:

    class IntParameter: public Parameter {
    public:
         virtual void accept(ParameterVisitor& v) {
              v.visit(*this);
         }
    };
    class FilenameParameter: public Parameter {
    public:
         virtual void accept(ParameterVisitor& v) {
              v.visit(*this);
         }
    };
    

    Note that in each accept member function, the type of *this is the static type of the class – namely, IntParameter& in the first case, and FilenameParameter& in the second case.

    You can then define a base class ParameterVisitor class like this:

    class ParameterVisitor {
    public:
        virtual ~ParameterVisitor() {} // Polymorphic classes need virtual dtors.
    
        virtual void visit(IntParameter& p) {}
        virtual void visit(FilenameParameter& p) {}
        /* .. etc. .. */
    };
    

    You can then subclass this visitor to get back the type information:

    class Gui1ParameterVisitor: public ParameterVisitor {
    public:
        virtual void visit(IntParameter& p) {
            /* ... use GUI1 to create a field for an integer. */
        }
        virtual void visit(FilenameParameter& p) {
            /* ... use GUI1 to create a field for a filename. */
        }
    };
    
    class Gui2ParameterVisitor: public ParameterVisitor {
    public:
        virtual void visit(IntParameter& p) {
            /* ... use GUI2 to create a field for an integer. */
        }
        virtual void visit(FilenameParameter& p) {
            /* ... use GUI2 to create a field for a filename. */
        }
    };
    

    Your ParameterList class can then just store a list of Parameter*s. You can then build the GUI by instantiating the appropriate visitor type and then having its visit callbacks do all the widget construction. This ends up being type-safe and recovers the information you need. It does have the drawback that every time you create a new parameter type, you have to add a new member function visit to the ParameterVisitor class, but you’d need to do that anyway to do all the GUI building.

    Hope this helps!

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

Sidebar

Related Questions

I have following models: class Category < ActiveRecord::Base has_many :items default_scope where(:enabled => true,
I have an algorithm that uses the following OpenSSL calls: HMAC_update() / HMAC_final() //
Currently im faced with the following problem: I have a script that searches through
Say I get the following question Console.WriteLine(Which teams have faced eachother? - use Red
we have faced a problem with our production system yesterday which I am unable
I am faced with the following issue. Consider the following class: //Will be similar
I'm faced with the following problem in rails. I have a form to edit/create
I was studying an algorithm book that faced to the following sentence. Please describe
When faced with a class that has multiple similar methods operating on different parameter
I have found this site very useful for all my previously faced problems, However

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.