Data Class Cyclic References
In this article, we discuss Data Classes and Data Entities (instance of a Data Class, objects).
In this context, cyclic graphs (for example Data Class structures with cyclic references) are not harmful per se. Some designs in computer engineering are based on circular references, such as the doubly-linked list, graph models, or computer language grammars. Nevertheless, cyclic structures are usually not necessary in the type of applications built with FNZ Studio. There are several good reasons why you should avoid them.
Cyclic data graphs are potentially dangerous on two main grounds.
-
First, circular references are fragile and easy to break.
-
Second, it is harder to test applications that contain circularly-referenced objects.
Please note that there is a difference between cyclic/recursive model definitions , such as in the case of the linked list, and cycles introduced at the instance level. Most problems arise because of cycles at the instance level.
Fragility
It isharder to understand data models that use cyclic references. If your application is easy to understand, it's easier to maintain, it helps you to avoid bugs, and making changes is safer.
For example, when inserting a new entity, it is not immediately clear at which locations the entity needs to be registered. Usually architects help themselves with the factory pattern. This pattern ensures that entities are created and registered in the required way. However, it introduces an additional level of complexity.
Testing
Cyclic structures cannot be tested in isolation from one another. Being able to test isolated parts of an application is the key to successful testing.
If you can only execute end-to-end tests, all boundary cases must be included. Usually this leads to a combinatorial explosion of execution paths that must be tested.
Before building circular references into your data model, give some thought to alternatives. A car needs to know which wheels it has, but does each wheel really need to know which car it belongs to?
The effort you put into making your data model cycle-free most likely outweighs the costs of maintaining and testing your application.