title: Extend a class in an existing architecture?
body: <p>The question is only relevant for typed programming languages, dynamic solutions aren't satisfying. Let's assume that the language is C++.</p>
  
  <p>Example architecture:</p>
  
  <pre><code>- DisplayObject (base class)
  -- Container (derived from DisplayObject)
  -- Sprite (derived from DisplayObject)
  </code></pre>
  
  <p>So I have a game engine in my hands and it only has X and Y coordinates. Let's say I want to add a Z coordinate. To do this, I'd have to modify the base class <code>DisplayObject</code>. Because if I simply derive from it to add the Z-axis functionality, it would make it impossible to use classes <code>Container</code> and <code>Sprite</code> in my code without casting them to my new <code>DisplayObject</code>.</p>
  
  <p>The question is, how to solve this without using casting?<br>
  There are dozens of classes derived from <code>DisplayObject</code>, so modifying them all one by one would look very weird.<br>
  I was also suggested delegation, but I don't see how to apply it here.</p>