Oovaide Index

Viewing a Class for Composition

Sometimes a class grows too large, and needs to be refactored. In some cases, it can be difficult to determine what will result in a clean separation of multiple classes.

The Oovaide program can display all of the data members and functions of a class and show how they are related. The C++ code is parsed and the diagrams are created automatically. The following shows a class portion diagram in the Oovaide program, and shows an example "Package" class. The data members are shown in rectangles, and the member functions are shown in ellipses. The arrows show the direction of the dependency.

Some notes about this example:

Run the following to view these diagrams.

CppParser Example

Now we move on to an example of a class that needs to be refactored. This class is used in the Oovaide .cpp parser. The Oovaide program shows that it is in the module with the highest number of lines in all of the Oovaide source code, although the complexity is not the highest. This class is not the cleanest class to analyze since it uses function pointers to global functions called by the clang visitor functions, but since this class was the inspiration for the portion diagrams, it seems like a worthy example.

For this refactoring, it is useful to think about how functions can be rearranged based on the data members.

An important aspect is to think about the lifetimes of the data members. The mOperation and mClassifier members are only used while parsing classes and operations.

CppParser Example - Post Refactor

For the first refactoring, the model data was moved into a new class called ParserModelData.

The portion diagram shows a bit more than a class diagram since a typical class diagram would only show the following.

The remaining CppParser class is shown below.

The improvements that resulted are:

At this point, there are some tradeoffs for refactoring further. The most likely candidates are to move the following data members into a CppOperationParser class: On the one hand, the CppParser class size would be reduced, and the operation parts would be separated, but on the other hand, leaving the CppParser class as is means it contains all parsing functionality.

Other Notes

Some other notes about portion diagrams: Other notes about the Oovaide program: