User login

Weekly Report




I've been looking at the best way to split up my library into a base Table Type Pattern parsing/validation portion and the rest of my code matching flows into this pattern.
This gives two advantages firstly it will help to make the code a little more manageable as it is getting fairly large with a lot the code being in a single file and also would allow a Table Type Pattern validation tool and viewer to be released without releasing the flow matching portion. Tools for dealing with Table Type Patterns are essentially non existent so this would be a useful to others.

The natural design of the Table Type Pattern code made this split difficult. A Table Type Pattern is a tree of nesting objects, of differing types dependent on where it is. For example a Flow will include a list of Instructions and a list of Matches, and that list of Instructions may include a list of Apply or Write Actions. My code has followed this pattern with objects initialisation creating children of the the expected type recursively until the entire TTP is loaded. My flow matching part works in a similar way by calling satisfies, which is then run recursively on the entire structure.

In this case traditional sub-classing does not work because all references in the parent object types would need to be updated to create the correct sub-class. A mapping could be used to ensure the correct class is created. However, all classes are already subclasses of TTPObject and some of TTPList - using a mapping would still not allow the base class to be updated because this is specified when a sub-classes are created.

As such I decided the best way to solve this problem was to create a decorator that allowed classes to be extended by merging a new class into the original, this looks similar to partial classes in C#. The method I used also allows fake subclassing by allowing the original version of a method to be called from the new version, while still writing the new one to the class. Due to how python creates classes updating a base class will apply to all sub-classes.

Once I figured out this method, I've made the split and I've also worked through tidying some of the docs and code as I go.