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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:57:06+00:00 2026-06-05T02:57:06+00:00

I have several complex classes, that are constructed using separate creator classes that inherits

  • 0

I have several complex classes, that are constructed using separate creator classes that inherits from the class to create.

One example might be a graph that is constructed from unordered data.

class Graph{
  //....
  public:
   void showData(); 
  protected: 
    std::vector<std::pair<int,int> > mConnectedData;

}

class GraphCreator:private Graph{
  public:
    //...
    void construct();
  private:
   std::map<double,int> mSomeHelperContainer;
   //...
}

For the construction I need many helper functions and also helper data, which I put in another class GraphCreator. Since many graph related functions are also necessary and since I need the data of the graph at any case I use private inheritance.
Since this is by no means the famous is-a relation and since private inheritance is generally considered a hint for bad design I have some doubts:
Is this a good Idea and one appropriate way to design a factory or are there some major drawbacks that I have no thought about ?
What would be a better way of designing a such a factory ?

Edit:

Thanks for the answers so far !
Some additional information to make the reason for the currently used approach clearer.
I cannot use a static creation method (far too many state variables in the Creator) and I have another constraint:
I want to provide the Graph independent from the creator (e.g together with a read from file method) in a library to other people.
Those should not have to care about the creator. Therefore I am also a little unsure about friend usage, since it adds code inside the Graph class.

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

    It is not a good way (inheritance from anything with data rarely is).

    The traditional approach is to either:

    • make GraphCreator a friend of Graph
    • implement the method as a static Build method in Graph (directly)

    The decision mainly depends on whether you need the “factory” to be stateful. A class is used to represent state, which a method cannot do.

    • Therefore if you need state you need a class to store it, and thus GraphCreator is your best bet.
    • For a stateless approach, the static method is much more lightweight.

    If you are undecided, pick the easiest (static method) and see how far it goes 🙂

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

Sidebar

Related Questions

I have a window that contains several rather complex views. Right now, I'm using
I have quite a complex entity structure where several classes inherit from a base
I have two classes: Employee and EmployeeGridViewAdapter . Employee is composed of several complex
I have several UIViews that have somewhat complex shapes that I have drawn via
I have a complex page that has several user controls like galleries, maps, ads
I have several buttons. When clicked I would like to remove all classes from
I use JAXB 2.1 to generate Java classes from several XSD files that I
I have a complex graph of XML-serializable classes that I'm able to (de)serialize to
I have several complex data structures like Map< A, Set< B > > Set<
I have several dates in mysql tables, using those dates I need to find

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.