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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:08:53+00:00 2026-06-18T02:08:53+00:00

I wasn’t really sure how to search for this question. I’m doing an embedded

  • 0

I wasn’t really sure how to search for this question.

I’m doing an embedded system design with the following scenario.

  • I have a main application class that needs to create a bunch of hardware interfaces such as a keypad, display, communication ports, etc… a whole slew of stuff

  • Now I have all these objets in the main application that I can use which is great

  • The application class contains a few sub classes that it can go into and stay for a while. One example is a menu class that it enters and runs inside that class until the menu is closed

  • I need the menu class to also interact with a lot of a hardware objects that were created at the application level

  • What is the best way to go about this without using global variables? Is there a good solution to this problem?

I could pass each object into the menu class, but I don’t want to create a constructor with 20 arguments. My current solution is to put all the objects into a structure and pass that structure into the sub-class constructor. That way they also have access.

The part that bugs me about this approach is that I have to define the structure outside of the application which I don’t really like. Something just keeps telling me it’s not the best solution.

Open to any suggestions.

  • 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-18T02:08:54+00:00Added an answer on June 18, 2026 at 2:08 am

    Presumably, there is ONE keypad – thus only one “Keypad Interface Object”, right? Similarly with Display [ok, there may be two displays, but still].

    So my suggestion would be to have a registration and a “container” that holds the registered interfaces something like this:

    class KeyPad
    {
     public:
        int getKeyPressed();
    };
    
    class Display
    {
      public:
         OutputText(std::string msg);
    };
    
    
    ... bunch of other stuff ... 
    
    class HardwareRegistry
    {
       priviate:
          Keypad  *keypad;
          Display *display;
    
          static HardwareRegistry *myself; 
    
       public:
          Keypad*  GetKeypad() { return keypad; }
          Display* GetDisplay() { return display; }
          void RegisterKeypad(Keypad *akeypad) { keypad = akeypad; }
          void RegisterDisplay(Display *adisplay) { display = adisplay; } 
    
    
          static HardwareRegistry* GetHwRegistry() 
          { 
             if (!myself) myself = new HardwareRegistry; 
             ASSERT(myself);  // If we don't have a pointer now, panic!
             return myself; 
          }
     };
    

    Then you just have a Singleton Pattern to provide your HardwareRegistry, and register the devices as you create them during hardware initialization.

    Of course, if you support different kinds of Keypads, Displays, etc, then you would implement those with a “interface baseclass”, and the registry returns the KeypadBase type, for example.

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

Sidebar

Related Questions

Wasn't really sure how to search for this... I have a the following which
Okay I wasn't really sure how to word this question, but basically what I
Wasn't really sure how to word the question ... I have a project and
I tried researching this but wasn't sure what to search for. I have a
I wasn't really sure if this was the right site to put this question
I wasn't sure exactly how to phrase the question Title. I have this block
I wasn't really sure how to title the question, but consider the following lua
I wasn't sure how to search for this. I have a swing application. I
I wasn't 100% how to phrase this question. I have a request to a
I wasn't even sure how to phrase this so you'll have to forgive me

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.