Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe there are <em>multiple</em> reasons for <strong>namespaces</strong>. One way I understand it is: <code>private</code>, <code>protected</code>, and <code>public</code> expressions help a lot in <em>team environments</em> so that other devs don't end up using <em>methods</em> you didn't intend them to. That being said, you only use <code>private</code> when methods or properties only need to be accessed by that same object. Use <code>protected</code> when you need an inheriting class to carry that same functionality and use <code>public</code> when an object of a different class needs to access your object.</p> <p>eg:</p> <p>Class <code>Victim</code> has</p> <ul> <li>private method haveAnxiety()</li> <li>public property appearsToBeRich:Boolean</li> </ul> <p>Class <code>Robber</code> has</p> <ul> <li>private method profile(obj:Victim)</li> <li>private method rob(obj:Victim)</li> </ul> <p><code>Robber-&gt;profile()</code> will need to access <code>Victim-&gt;appearsToBeRich</code>. If <code>Victim-&gt;appearsToBeRich</code> returns <code>true</code>, then that <code>Victim</code> object will get <em>robbed</em>. a <code>Robber</code> object never needs to run <code>Victim-&gt;haveAnxiety</code> as the <code>Victim</code> will run <code>this-&gt;haveAnxiety()</code> as soon as that <code>Victim</code> object starts getting robbed.</p> <p>Granted, real world examples are a <strong>LOT</strong> more complex than my example (and I hope they are much more <em>graceful</em>). Anyway, I hope that helps.</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