Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I am not too sure what the name of this is called...</p> </blockquote> <p>I am having trouble following your pseudo-code, but you might be able to accomplish what you're looking for via:</p> <ul> <li><a href="http://en.wikipedia.org/wiki/Inheritance_%28object-oriented_programming%29" rel="nofollow">Inheritance</a>, which allows derived classes to access <em>protected</em> variables from a base class (static or instance variables)</li> <li><a href="http://en.wikipedia.org/wiki/Friend_function" rel="nofollow">Friend functions</a> (C++) (which allows functions to have access to private instance variables on a class)</li> <li><a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow">Dependency Injection</a> (But probably only if you have more complex requirements than you're actually stating in your question. In this super-simple case, you'd just be accessing public properties or fields when an instance is passed in to a function - you might have to access them through a public getter/setter, since you want the variables to be private)</li> </ul> <p><strong>Edit:</strong></p> <p>After your edits, it is pretty clear that you want <a href="http://en.wikipedia.org/wiki/Observer_pattern" rel="nofollow">the Observer Design Pattern</a>. This allows you to decouple the code that responds to a state change from the code that signals the state change.</p> <p>That pattern is less about access to variables (as my first links were about), than it is about responding to events (or "state transitions", if you think about your class as a <a href="http://en.wikipedia.org/wiki/Finite-state_machine" rel="nofollow">Finite State Machine</a>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload