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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:25:55+00:00 2026-06-13T05:25:55+00:00

For one of my current projects I have an interface defined for which I

  • 0

For one of my current projects I have an interface defined for which I have a large number of implementations. You could think of it as a plugin interface with many plugins.

These “plugins” each handle a different message type in a network protocol.
So when I get a new message, I loop through a list of my plugins, see who can handle it, and call into them via the interface.

The issue I am struggling with is how to allocate, initialize, and “load” all the implementations into my array/vector/whatever.

Currently I am declaring all of the “plugins” in main(), then calling an “plugin_manager.add_plugin(&plugin);” for each one. This seems less than ideal.

So, the actual questions:
1. Is there a standardized approach to this sort of thing?
2. Is there any way to define an array (global?) pre-loaded with the plugins?
3. Am I going about this the wrong way entirely? Are there other (better?) architecture options for this sort of problem?

Thanks.

EDIT:

This compiles (please excuse the ugly code)… but it kind of seems like a hack.
On the other hand, it solves the issue of allocation, and cleans up main()… Is this a valid solution?

class intf
{
public:
    virtual void t() = 0;
};

class test : public intf
{
public:
    test(){}
    static test* inst(){ if(!_inst) _inst = new test; return _inst; }
    static test* _inst;
    void t(){}
};
test* test::_inst = NULL;

intf* ints[] =
{
    test::inst(),
    NULL
};
  • 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-13T05:25:57+00:00Added an answer on June 13, 2026 at 5:25 am

    Store some form of smart pointer in a container. Dynamically allocate the plugins and register them in the container so that they can be used later.

    One possible approach for your solution would be, if you have some form of message id that the plugin can decode, to use a map from that id to the plugin that handles that. This approach allows you to have fast lookup of the plugin given the input message.

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

Sidebar

Related Questions

In one of my current projects I have a dropdown (select) form element. I
could someone one the current list of managed Beans or classes in Java EE
I have a navigation bar and I need to always keep the current one
My current project is getting awfully large. I have dozens of activities, adapters, fragments,
I have several projects which are under git repositories. All projects have its own
I have an application architecture which has following layers (or c# projects). web front
I'm using a third party C++ lib in one of my current projects. Their
For one of my current iOS project, some business logic has been provided to
One of the data structures in my current project requires that I store lists
for my current project I am using Castle's ActiveRecord in C#. For one of

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.