Single Object accessed my more than 1 object

I’m working on a project that has a thermistor in it. The thermistor data is used by a controller to turn heaters and coolers on and off and is used by a display that outputs it’s information to the user. The thermistor object has all the usual get(), set(), read() methods.

What I want is to have my controller object and my display object access the thermistor object without passing the data up to the main loop and then back down. So graphically I want this:

      Main Loop
      /       \
Contoller    Display
      \       /
      Thermistor

Instead of this:

      ______Main Loop______
      /          |        \
Thermistor   Controller   Display

How do I set this up with classes and objects? Or is there a better way to do this? I haven’t been able to find the right search terms I always end up reading the same things about inheritance which isn’t what I want to do here.

Thanks!

If your methods are public your other classes just need a reference to the Thermistor object (either as Thermistor* or Thermistor&).
This could be stored in a private field of each of the objects.

It’s doable and not difficult, but the crunch-question is: "Does this relation really make sense?"
Only you can answer this for your own project.

2 Likes