title: Best practice: A compose B, DerivedA compose DerivedB
body: <ul>
  <li>struct <code>B</code> holds data.</li>
  <li>struct <code>DerivedB</code>: <code>B</code> adds some specific data to <code>B</code>.</li>
  <li>class <code>A</code> holds a reference to an object of type <code>B</code>.</li>
  <li>class <code>DerivedA</code> holds a reference to an object of type <code>DerivedB</code>.</li>
  </ul>
  
  <p>Is it inherently a bad design?</p>
  
  <p>If not, what is the <strong>best way of achieving that</strong>?</p>
  
  <pre><code>class A
  {
  public:
      A() :m_b(std::make_unique&lt;B&gt;(B())) {}
      B&amp; getB() { return *m_b; }
  protected:
      A(std::unique_ptr&lt;B&gt; b):m_b(std::move(b)) {}
  private:
      std::unique_ptr&lt;B&gt; m_b;
  };
  
  class DerivedA : public A
  {
  public:
      DerivedA() :A(std::make_unique&lt;B&gt;(DerivedB())) {}
      DerivedB&amp; getDerivedB() { return static_cast&lt;DerivedB&amp;&gt;(getB()); }
  };
  </code></pre>
  
  <p>Is this solution, which uses a cast, the best?</p>