Design pattern for truncating a large object graph

Using Java, I have a very large graph of objects, where an object is associated with many other objects, each of which is associated with many more other objects. Most of the time I just need subgraph to go to the method or send over the network.

Is there a recommended design pattern, so I can truncate this graph of a large object at many points in the graph. One way would be to provide NULL as a reference at all truncation points. I would appreciate any other ideas.

thanks

+4
source share
3 answers

If you understand correctly, you can use Lazy Factory .
This strategy is usually used when matching an object with associations that you don’t need right now, and may not be needed at all. (It is widely used in Hibernate ORM).
When you want to send large objects over the network, you can use a proxy template.

+1
source

One option is to build a graph from Node objects (as you are doing now), and then to truncate the graph, encapsulate it using the Graph object, which stores the graph as a member, provides its own interface for performing operations on the graph and internally uses a table of nodes that should be considered deleted from the graph.

The advantage of this approach is that you do not mutate the original graph object, and you also do not need to copy it.

0
source

A proxy pattern is a good design pattern for this problem.

0
source

Source: https://habr.com/ru/post/1440100/


All Articles