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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:27:22+00:00 2026-05-10T15:27:22+00:00

Suppose I have a design like this: Object GUI has two objects: object aManager

  • 0

Suppose I have a design like this:

Object GUI has two objects: object aManager and object bManager, which don’t ever talk to each other.

Both aManager and bManager have object cManager as an attribute (or rather a pointer to cManager). So when aManager modifies its cManager, it’s affecting bManager’s cManager as well.

My question is what is the correct way to design/implement this?

I was thinking of making cManager as an attribute of GUI, and GUI passes a pointer to cManager when constructing aManager and bManager. But IMHO, GUI has nothing to do with cManager, so why should GUI have it as an attribute?

Is there a specific design pattern I should be using here?

  • 1 1 Answer
  • 3 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-10T15:27:23+00:00Added an answer on May 10, 2026 at 3:27 pm

    I’m going to interpret this as simply as possible, if I’m not answering your question, I apologize.

    When you really get the answer to this question, it’s your first step to really thinking Object Orientedly.

    In OO, when two objects both ‘has a’ ‘nother object, it’s perfectly acceptable for both to refer to that other object. The trick with OO is that objects have a life of their own, they are fluid and anyone that needs them can keep a reference to them. The object must keep itself ‘Valid’ and maintain stability when being used by many other objects. (This is why immutable objects like String are so great, they are ALWAYS as valid as the second they were created)

    The one exception is if you are coding in C++ because then you actually have to manually free objects, that implies an owner that can monitor each object’s lifecycle–that makes it really really hard to ‘Think’ in OO in C++.

    [Addition] Since you are referring to pointers, I’m thinking you are programming in C++ which is different. In that case, you are right. Make one manager ‘Own’ the lifecycle of your shared object. It must not let that object die until all other references have gone away.

    You can also use reference counting. Whenever someone gets a reference to your object, it calls ‘addReference’ or something, whenever it’s done it removes the reference. If anyone calls removeReference when the count is 1, the object can clean itself up. That’s probably as close as you can come to true OO-style allocation/freeing in C++. It’s very error-prone though.

    There are libraries to do this kind of stuff I believe.

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

Sidebar

Related Questions

No related questions found

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.