Sunday, February 15, 2015

Program Reader Class – Call Chain Removal

As mentioned recently, having a chain of function calls is not good object-oriented design because it requires the initial caller to have knowledge of the internal members of each of the subsequent objects in the chain breaking encapsulation.  The table operand text virtual function contained this call chain:
return programLineReader.unit()->dictionary(m_operandType)->string(operand);
Before removing this call change and the equivalent one in the table remove virtual function, some code rearrangement was performed.  This included renaming the Program Line Reader class to simply Program Reader since it reads more than just from a program line (it also access a dictionary).  The Program Reader class and its functions were also moved to their own header and source files.

The get string for operand function was added with an operand type argument.  This eliminated the call chain in the operand text function, which now for clearly reads:
return programReader.getStringForOperand(m_operandType);
To prevent a call chain in this new function (though with one less function call), the get string from dictionary function was added to the program model class with operand type and operand arguments.  An internal read operand function was added for clarity because calling the function operator function internally is the not very self-explanatory this->operand()().

Similarly, the remove reference to operand function with an operand type argument was added for the remove table function along with a remove reference from dictionary program model function with the operand type and operand arguments.

The unit access function, which allowed the call chain in the first place, was no longer used and was removed.  This takes care of the function call chains when reading from the program.  The function call chain when writing to the program will be eliminated next.

[branch table commit 0e6751f023]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)