title: How to design OO graph node classes with improved usability & readability?
body: <p>This is a basic OO design question. I'm writing classes in C++ to represent items in a flow chart according to an input C file that have been parsed.</p>
  
  <p>Simply we have 2 types of items (classes) : <strong>FlowChartActionItem</strong> and <strong>FlowChartConditionItem</strong>. 
  These represent Actions and Decision/Condition elements of a flowchart respectively. And they also represent Statements and If-conditions respectively, that existed in the input C file. Both classes inherit <strong>FlowChartItem</strong>.</p>
  
  <p>Each sub-classes has a number of pointers to the items that comes after them; yes, we have a graph, with nodes(items) and links(pointers). But the <strong>FlowChartActionItem</strong> has only one outward pointer while the <strong>FlowChartConditionItem</strong> has 3 outward pointers (for the then-statements branch, the else-statements branch and a pointer to whatever comes after the both branches of the if-condition.</p>
  
  <p>My problem is writing a neat setter for the outward pointers (nextItems). Take a look at the classes :</p>
  
  <pre><code>class FlowChartItem
  {
  public:
      //I **need** this setter to stay in the parent class FlowChartItem
      virtual void SetNextItem(FlowChartItem* nextItem, char index) = NULL;
  };
  </code></pre>
  
  <p>-</p>
  
  <pre><code>class FlowChartActionItem:public FlowChartItem
  {
  public:
      FlowChartItem* nextItem; //Only 1 next item
  public: 
      void SetNextItem(FlowChartItem* nextItem, char index);
  };
  </code></pre>
  
  <p>-</p>
  
  <pre><code>class FlowChartConditionItem: public FlowChartItem
  {
  public:
      FlowChartItem* nextItem;
      FlowChartItem* trueBranchItem;
      FlowChartItem* falseBranchItem; //we have 3 next items here
  public:
      void SetNextItem(FlowChartItem* nextItem, char index);
  };
  </code></pre>
  
  <p>I needed a generic setter that doesn't depend on the number of pointers the sub-class is having.
  As you see I've used char index to tell the setter which pointer is to be set. But I don't like this and I need to make things neater. Because code won't be readable e.g :</p>
  
  <pre><code>item1.setNextItem(item2,1);
  </code></pre>
  
  <p>we don't remember what the 1 means? the then-branch ? the else ? ??</p>
  
  <p>The obvious answer is to define an enum in FlowCharItem, but then we'll have one of two problems :</p>
  
  <p>1- Enum values will be defined Now and will thus be tailored for the current sub-classes FlowChartActioItem and FlowChartConditionItem, so calls to SetNextItem on future sub-classes will have very bad readability. And even worse, they cannot have more than 3 outward pointers!</p>
  
  <p>2- Solve the 1st problem by making developers of the future sub-classes edit the header file of FlowChartItem and add whatever values in the enum ! of course not acceptable!</p>
  
  <p>What solution do I have in order to keep
  -good readability
  -neat extensibility of my classes ??</p>