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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:35:34+00:00 2026-05-28T07:35:34+00:00

I have some deep question about OOP architecture. What is a proper way to

  • 0

I have some deep question about OOP architecture.

What is a proper way to communicate between object and its members?

Let me explain what I mean by some examples. (I use C++, but it’s not related to the question at all.)

class Shield
{
    int toughness;
    //...

    void broke();
};

class Human
{
    String name;
    int age;
    //...
    Shield my_shield;

    void scream();
    void equip_shield(Shield);
};

Human vadim;
Shield aegis;

vadim.equip_shield(aegis);
aegis.destroy();

So, now I want human to scream every time his or her shield is destroyed. But shield has no way to call its owner’s method. He just doesn’t know who is its owner.

One more example.

class Human
{
    //...
    void die();

};

class Crowd
{
    vector<Humans> people;
    //...
};

So, now I want crowd to tell all people to leave it if there are less than 10 people in the crowd. It’s OK to crowd to tell such commands, but this check must be performed every time somebody dies in the crowd. So, again, human must somehow inform crowd that he or she is dead and ask crowd to recheck numbers of people in it.

The clear way to sort out this situation is to save the pointer to the crowd in every human. But it’s dump way, because human can be in many crowds. Also there is synchronization problem here (same problem, actually, how can crowd know about the fact John left it?).

I believe that some trigger mechanism exists to solve such kinds of problems.

Thanks.

  • 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-05-28T07:35:35+00:00Added an answer on May 28, 2026 at 7:35 am

    What you are looking for is the observer pattern.

    With the observer pattern the crowd would subscribe to the humans in the crowd and when a human emits the “death” status it can recheck the count.

    Likewise for the shield that could fire a “shield broke” event that the human could recognize and start yelling.

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

Sidebar

Related Questions

Explanation: Let's say I have an object graph that's nested several levels deep and
I have a small question: Foo *myFoo; myFoo = new Foo(anotherFoo); // some deep
I have a crash that is happening deep within UIKit for some reason; an
I have a question about binary serialization in C# I need to be able
This is not a question about putting std::auto_ptr into std::vector. Is there some vector
I was answering some quiz questions for an interview, and the question was about
A question I have been thinking about for a while - would Stackoverflow users
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart

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.