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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:48:12+00:00 2026-05-11T05:48:12+00:00

In my application, there are 10-20 classes that are instantiated once[*]. Here’s an example:

  • 0

In my application, there are 10-20 classes that are instantiated once[*]. Here’s an example:

class SomeOtherManager;  class SomeManagerClass { public:     SomeManagerClass(SomeOtherManager*);     virtual void someMethod1();     virtual void someMethod2(); }; 

Instances of the classes are contained in one object:

class TheManager { public:     virtual SomeManagerClass* someManagerClass() const;     virtual SomeOtherManager* someOtherManager() const;     /** More objects... up to 10-20 */ }; 

Currently TheManager uses the new operator in order to create objects.

My intention is to be able to replace, using plugins, the SomeManagerClass (or any other class) implementation with another one. In order to replace the implementation, 2 steps are needed:

  1. Define a class DerivedSomeManagerClass, which inherits SomeManagerClass [plugin]
  2. Create the new class (DerivedSomeManagerClass) instead of the default (SomeManagerClass) [application]

I guess I need some kind of object factory, but it should be fairly simple since there’s always only one type to create (the default implementation or the user implementation).

Any idea about how to design a simple factory like I just described? Consider the fact that there might be more classes in the future, so it should be easy to extend.

[*] I don’t care if it happens more than once.

Edit: Please note that there are more than two objects that are contained in TheManager.

  • 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. 2026-05-11T05:48:13+00:00Added an answer on May 11, 2026 at 5:48 am

    I think there are two separate problems here.

    One problem is: how does TheManager name the class that it has to create? It must keep some kind of pointer to ‘a way to create the class’. Possible solutions are:

    • keeping a separate pointer for each kind of class, with a way to set it, but you already said that you don’t like this as it violates the DRY principle
    • keeping some sort of table where the key is an enum or a string; in this case the setter is a single function with parameters (of course if the key is an enum you can use a vector instead of a map)

    The other problem is: what is this ‘way to create a class’? Unfortunately we can’t store pointers to constructors directly, but we can:

    • create, as others have pointed out, a factory for each class
    • just add a static ‘create’ function for each class; if they keep a consistent signature, you can just use their pointers to functions

    Templates can help in avoiding unnecessary code duplication in both cases.

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

Sidebar

Related Questions

Is there a quick way to detect classes in my application that are never
I am developing an asp.net mvc application, which has these enity classes: public class
Here is the problem I'm running into. There's a huge legacy application that runs
I have a Silverlight application that retreives a list of serializable classes. In these
For my application there are several entity classes, User, Customer, Post, and so on
In a large Application is there any way to distinguish user-defined classes with built-in
In our legacy Java EE application, there are loads of value object (VO) classes
In my web application there is a process that queries data from all over
I have an application that uses several different Java classes and would like to
Is there a way to enumerate all QObject classes declared in an application or

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.