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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:45:04+00:00 2026-06-07T02:45:04+00:00

I have a design problem. I have a polymorphic structure with an interface A

  • 0

I have a design problem.

I have a polymorphic structure with an interface A (abstract one) and a workflow implemented in class W which uses the interface A without knowing the derived classes. This is implemented in DLL1 and I have a factory interface F capable of returning A*.
In DLL2, I have the concrete implementations of A, which could be A1, A2 etc. and a factory implementation F1 capable of creating A1 and A2 instances.

The factory interface which I have is something like this.

enum ObjectType{typeA1, typeA2};

class F
{
    public:
    A* create(enum ObjectType) = 0;
}

Some client class which knows both DLL1 and DLL2 will give me the concrete object type.

But this is ugly since I will have to know the possible types of the concrete classes upfront when I write my DLL1. And this almost defeats my purpose of the polymorphic design. I don’t want to do this.

The alternative option which I can think of is to use strings, instead of the enumeration. But, I like to avoid strings as they are not type-safe and are prone to errors. I wish I had a chance to extend the enums by inheritance, just like the classes.

My questions :

Is there a better way out?
Is extension of enums possible in C++11? (I don’t have it now, though)

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

    You can modify your abstraction to allow the user of interface A to also provide the particular factory that creates it. (instead of providing an enum).

    // In DLL1
    class AbstractF {
    public:
        virtual A * create () = 0;
    };
    
    template <typename ConcreteA>
    class ConcreteF : public AbstractF {
    public:
        A * create () { return new ConcreteA; }
    };
    

    Now, each ConcreteF<> would need to be passed into code to DLL1 for those parts of the framework that need to create the right concrete instance of A. Thus, the framework user must inform the framework which of A1 or A2 to create not by passing in an ObjectType, but by passing in the correct ConcreteF (namely ConcreteF<A1> or ConcreteF<A2>).

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

Sidebar

Related Questions

I have a re-occurring design problem with certain classes which require one-off initialization with
The problem is mostly OOP design problem. I have a class which handles the
I have a design problem: Question class: have a question and answer (String) TextQuestion
I have a problem here that requires to design a data structure that takes
This is more of a design problem then a programming one. I have a
I have a class design problem that could simplified with this example: // foo.h
I have a design problem which I would like some input on. Here are
I have a design problem. I have two data objects which are instances of
I've got a design problem in a C++ project. I have a class, named
There is a design problem like this. Suppose you have a set of class

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.