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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:50:49+00:00 2026-06-12T06:50:49+00:00

I have three classes that are closely coupled to each other, and I would

  • 0

I have three classes that are closely coupled to each other, and I would like to specialize all three simultaneously. The three derived classes should talk to each other with the same interfaces as the superclasses, plus some additional interfaces I will add in the derived versions. Is there a reasonable pattern I can use to implement this kind of “simultaneous derivation” relationship in C++?

To be more specific: I’m extending a UI component that displays and edits a graph. There are three classes involved:

  • CGraph, the UI widget itself;
  • CSeries, which holds the data and is operated upon by CGraph;
  • CValue, representing one value in the series, a list of which is owned by CSeries.

I plan to add derived classes CNewGraph, CNewSeries, and CNewValue (placeholder names).

CGraph     ---views/edits--->  CSeries     ---owns list of--->  CValue
  ^                              ^                                ^
  | is-a                         | is-a                           | is-a
  |                              |                                |
CNewGraph  ---views/edits--->  CNewSeries  ---owns list of--->  CNewValue

The kind of problem I run into with this is that CSeries, for instance, refers to CValue in its definition:

class CSeries
{
public:
    CValue & FindValue(/* stuff */);
private:
    vector<CValue> m_values;
};

In CNewSeries, that should be a vector of CNewValue instead, and FindValue should return a CNewValue reference, etc. Similarly, CGraph refers to CSeries in its definition, but CNewGraph should use CNewSeries instead.

  • 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-12T06:50:51+00:00Added an answer on June 12, 2026 at 6:50 am

    One possibility is to templatize CSeries based on the value type. Then you can create a derived class that specifies a specific value type to use, or even a typedef if no additional members are needed.

    template <typename T>
    class CSeriesBase
    {
    public:
        T & FindValue(/* stuff */);
    private:
        std::vector<T> m_values;
    };
    
    typedef CSeriesBase<CValue> CSeries;
    
    class CNewSeries : public CSeriesBase<CNewValue>
    {
        /* additional members */
    };
    

    However, this breaks the inheritance relationships, so CNewSeries now does not derive from CSeries. This means anything else that uses CSeries cannot seamlessly use CNewSeries. In particular, CGraph needs to be templatized as well, on the series type this time.

    template <typename T>
    class CGraphBase
    {
    public:
        void SetSeries(T * pSeries);
    private:
        T * m_pSeries;
    };
    
    typedef CGraphBase<CSeries> CGraph;
    
    class CNewGraph : public CGraphBase<CNewSeries>
    {
        /* additional members */
    };
    

    For only three classes, this is not too bad, though I can imagine it getting cumbersome in a hurry if you had many more classes needing to talk to CSeries.

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

Sidebar

Related Questions

I have three classes that all have a static function called 'create'. I would
I have three JUnit test classes that all had some common code, including identical
I have Three different classes that all need to use instances of one class.
I have three classes that will each return a slightly different result. // interfact
As of the moment, I have three classes that each have instances of UIManagedDocument
I have three classes that I am using and have shortened for ease of
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
I have three classes that need to be related, and I'm not sure how
I have three classes ( Carnivore , Herbivore , and Plant ) that extend
I have three classes that pose a problem when trying to add a new

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.