jeudi 10 juin 2021

Best way to deal with large recurent class hierarchies

I am currently working on a project which involves writing an AST parser for a reasonably complex system based on Coq.

The goal is to map the expressions returned from this system into a tree data structure that can be easily worked with and extended later. This leads to an extensive class hierarchy due to the many data types involved, which becomes unmaintainable.

As I am primarily concerned about the extensibility of both the parser (adding support for a new type should be pretty simple) and of its consumers ( it should be easy to add new functionality, e.g. export to HTML), I wonder which patterns might help tackle the complexity of this system.

To solve some of the issues regarding adding new functionality, I implemented the Visitor pattern. However, I do still struggle with the first aspect, dealing with the large class hierarchy.

You can see a simplified example of the class hierarchy in the diagram below.

A simplified UML diagram for the current class hierarchy.

In the actual use-case, around 20 classes are inheriting the abstract class, with much more possibly being added in the future. Are there any patterns in particular I should look at to make this inheritance simple while still allowing for extensibility?

Aucun commentaire:

Enregistrer un commentaire