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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:14:20+00:00 2026-06-01T12:14:20+00:00

I have an object of class Message, which can be written and subsequently updated.

  • 0

I have an object of class Message, which can be written and subsequently updated. As far as I can see, MessageUpdate IS-A MessageWrite:

class MessageWrite
{
  protected:
    void setVersion(int version_) {...}
    void setReceiveTime(int tmReceive_) {...}

    Message _msg;
};


class MessageUpdate:public MessageWrite
{
    //ONLY setVersionShould be accessible here, NOT setReceiveTime
};

Is there a combination of method access level and inheritance level that can help achieve this?

I know that MessageUpdate can be simply made base class, but there’s the rub: it leads to diamond pattern in case i want to extend the message class. Consider:

class MessageUpdate {...};
class MessageWrite: public MessageUpdate {...};


//Now, while extending:
class AdminMessageUpdate:public MessageUpdate {...};
class AdminMessageWrite: public AdminMessageUpdate, public MessageWrite //DIAMOND Pattern!!

Where’e the gap in my understanding of inheritance? And is there any completely different way to achieve this logic without the multiple inheritance (as shown in latter code piece)?

  • 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-01T12:14:21+00:00Added an answer on June 1, 2026 at 12:14 pm

    Since all members of MessageWrite are protected, you could just make setReceiveTime() private inside MessageUpdate, so classes inheriting from MessageUpdate would not be able to access it. But I still have some issues with your design, such as:

    How is it that your design avoids the diamond? Wouldn’t it equally lead to:

    class MessageWrite {...};
    class MessageUpdate: public MessageWrite {...};
    
    //Now, while extending:
    class AdminMessageWrite:public MessageWrite {...};
    class AdminMessageUpdate: public AdminMessageWrite, public MessageUpdate //DIAMOND Pattern!!
    

    Why do you think MessageUpdate IS-A MessageWrite when you later say it is not (by specifying that not all of MessageWrite applies to it)? If this code must not be valid:

    MessageWrite& m = MessageUpdate();
    m.setReceiveTime(); // Should this be valid?
    

    then MessageUpdate IS-NOT-A MessageWrite. If my code should be valid, then there is no reason to avoid access to setReceiveTime() in MessageUpdate.

    And you would probably be better off by creating a base class AdminMessage and then inheriting directly from it to avoid the diamond:

    class MessageWrite {...};
    class MessageUpdate: public MessageWrite {...};
    
    //Now, while extending:
    class AdminMessage {...};
    class AdminMessageWrite: public MessageWrite, public AdminMessage {...};
    class AdminMessageUpdate: public MessageUpdate, public AdminMessage {...}; // No diamond
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a serializable Message class that has a Data As Object property that
I have an object class called BOM. It has a method, getChildItem() which returns
I have an object (Ticket), which has a list of other objects (Message). Message
I have written a program which uses a SQL exception class and then use
I have a business object class BusinessObject which implements an interface IAlternateInterface. I already
I have an object which hold a message in many language this is called
I have this object: class a { public string Application; public DateTime From, To;
I have an object of class F. I want to output the contents of
I have an object now: class Items attr_accessor :item_id, :name, :description, :rating def initialize(options
it's possible to have one entity object (class, e.g. User) for more entity models

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.