title: How to abstract away the interface to two similar classes?
body: <p>I'm writing an <a href="https://en.wikipedia.org/wiki/Ultimate_tic-tac-toe" rel="nofollow noreferrer">Ultimate Tic-Tac-Toe</a> engine as a programming exercise (for myself, not homework) and I have two similar classes. One is a class <code>MiniBoard</code> that contains a single normal Tic-Tac-Toe board, and another <code>Board</code> that is itself a large Tic-Tac-Toe board conisiting of 9 <code>MiniBoards</code>, one for each large cell in the game.</p>
  <p>I also have a function <code>int getState( ... )</code> that returns a certain number depending on whether a board is won, lost, drawn or in-progress. Since there is obvious symmetry between <code>MiniBoard</code> and <code>Board</code> it appears to me that I should be able to make my <code>getState</code> function accept both <code>MiniBoard</code> and <code>Board</code> as an argument, afterall they both must be either won, drawn, lost or in-progress.</p>
  <p>At first I thought to make <code>Board</code> inherit from <code>MiniBoard</code>, but this approach turned out unnecessarily complicated because the functionality of <code>MiniBoard</code> is fundamentally different from <code>Board</code>, even though they do represent very similar objects. It also doesn't really follow the &quot;IS A&quot; relationship of OOP inheritance.</p>
  <p>The idea that I currently have, but don't know if is any good, is to make an abstract base class <code>BaseBoard</code> that defines the common properties and methods as virtual and then have <code>Board</code> and <code>MiniBoard</code> derive from <code>BaseBoard</code>. Then I would define my function for getting the state as:</p>
  <pre><code>int getState(const BaseBoard &amp;board)
  </code></pre>
  <p>The main issue I have with this approach is that I don't know upfront what kinds of properties and methods will I need for my BaseBoard down the line. And if I ever get the the point of having a large chain of inheritance that starts with BaseBoard and wanting to change something, that would mean I would have to change every class definition down the chain of inheritance. What is the solution to this issue? Just derive more classes?</p>
  <p>All in all, is this a good way to solve the problem? And what are the pros and cons? I'm not very familiar with abstract base classes in C++. Any help is appreciated.</p>