title: Class instance interactions
body: <p>Variations on python class implementation where instances interact</p>
  
  <p>I've written three versions on my menu system class. They where:</p>
  
  <pre><code>class Menu(object)
  </code></pre>
  
  <p>The menu instances are stored in <code>__dict__</code>. I refer to menu data with <code>self.data</code>.</p>
  
  <pre><code>class Menu(dict)
  </code></pre>
  
  <p>The menu instances are stored in the dict subclassed by my class. I refer to menu data with <code>self[data]</code>.</p>
  
  <pre><code>class Menu(object)
  </code></pre>
  
  <p>The menu data is stored in a <code>cls.data</code> dict that I establish in <code>__init__()</code>. The class is mostly a method container and I don't benefit from the instance member features.</p>
  
  <p>Each has their positive and negative aspects but they all smell bad. I think what I have learned is that if you develop a class where one instance has to be able to interact with another instance, the schema falls apart since one method may need to transition between instances.</p>
  
  <p>For example, if I have a front panel LCD with a Main Menu screen and four hotkeys to select other menus, some methods will need to be able to navigate across instance boundaries and this is totally kicking my butt. When something is this unpleasant, it usually means that there is something important to learn. So, can any of you help me out? How can you best write code where instances interact within a method?</p>
  
  <pre class="lang-none prettyprint-override"><code>           Main Menu
  
    Port    Network    Device
   Setup     Setup      Setup     Next&gt;
  </code></pre>
  
  <p>When I push the button under Port Setup, the <code>Menu</code> class needs to switch its instance from the Main Menu instance to the Port Setup instance using a method that belongs to the class/instance. But how?</p>
  
  <pre class="lang-none prettyprint-override"><code>         Port Setup Menu
  
    Baud      Stop    Parity    Protocol
    Rate      Bits     Bit      Address
  </code></pre>