Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 59: Recursive object references in persistence objects
March 7, 2015 by markpiller
Spread the love

A recursive reference is when an object is either directly or indirectly references itself. This design pattern happens rather frequently in applications and quite often distributed systems do not handle it gracefully. Not Backendless – we fully support object recurrence as the same below demonstrates. Consider the following class:

Not only the class references itself through the “mom” and “dad” fields, it also includes the “children” field which may creates a recursive dependency. For example, suppose a person named Bobby has mom and dad named Jennifer and Richard accordingly. Both objects representing the mother and the father refer back to Bobby through the “children” field. The code below demonstrates that structure and saving it in Backendless using the Data storage API:

Asynchronous API (Android and Plain Java):

Synchronous API (Plain Java only):

Asynchronous sample: 

Synchronous sample: 

Asynchronous sample: 

Synchronous sample: 

Once you run the code, the data structure created in Backendless fully reflects the relationships created in the code. See a screenshot of the Person data table:
recursive objects backendless - Feature 59: Recursive object references in persistence objects

The structure in the data table may appear complex, however, it fully resembles the object hierarchy created in the code. Bobby has mom Jennifer and dad Richard. Both Jennifer and Richard have a child with the object ID from Bobby.

This is some complex stuff which we made look simple and we truly hope you will enjoy using it in your apps!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+