title: Different class modes: conditional constructors/methods vs inheritance?
body: <p>I currently own a custom peripheral with 8 red lights (first byte), 8 switches (second byte), 4 push button and 4 green lights (third byte). Instead of having to manipulate the hardware with low level instructions each time, I decided to make a class specially for this. Within this class, I decided to create 3 possible modes the peripheral could adopt:</p>
  
  <p>1- DEFAULT: each control is controlling the light above them; each light is then dependant to each control and thus their status can't be controlled by the program itself.</p>
  
  <p>2- MAPPABLE : each control can now have a custom behavior; each light is then independant to each control and thus their status can be controlled by the program itself.</p>
  
  <p>3- ANIMATION : each control is now disabled and you can choose in a wide variety of light animations.</p>
  
  <p>These three modes are all stored in a Enum:</p>
  
  <pre><code>enum Mode { DEFAULT, MAPPABLE, ANIMATION };
  </code></pre>
  
  <p>Now here are my constructors:</p>
  
  <pre><code>ZeBox(Mode mode = DEFAULT);
  ZeBox(std::bitset&lt;4&gt; lightsGreen, Mode mode = DEFAULT);
  ZeBox(std::bitset&lt;8&gt; lightsRed, Mode mode = DEFAULT);
  ZeBox(std::bitset&lt;4&gt; lightsGreen, std::bitset&lt;8&gt; lightsRed, Mode mode = DEFAULT);
  </code></pre>
  
  <p>The problem is as follow: if I decide to initialize lights' status, the mode <strong>CAN'T</strong> be DEFAULT, because like I said, lights status in DEFAULT mode are only dependant to controls, and not the program itself. However, the lights status in the two other modes (MAPPABLE and ANIMATION) <strong>CAN</strong> be both affected by the program.</p>
  
  <p>This is the kind of thing that can be resolved by using inheritance (each mode/class, for instance 'DefaultZeBox', 'MappableZeBox' and 'AnimationZeBox', has a custom constructor with custom methods and they all derive from the base class 'ZeBox'), but there would be one problem: how would I be able to change the peripheral mode with a method? I know I could do it by simply use polymorphism and instantiate a new object each time, but I did this class to make it easy to newcomers and I wanted to make a method for that purpose (like 'SetMode(Mode new_mode)'). However, if I don't use inheritance, I would have to find a way to "enable/disable" methods depending on the mode you choose.</p>
  
  <p>I would prefer to use inheritance, but I don't know how I would be able to change the mode with a method.</p>
  
  <p>Any idea?</p>