I know circular references (class a contains class b, and class b contains class a). But since I have not programmed enough, it is difficult for me to find reasons for using them. I was wondering if people can give me some good examples and perhaps explain the good reasons for using them.
For example, right now I am looking at 2D tutorials on the source code, and the user has created a Creature and a CreatureAi class that reference each other. For what reason? I don’t know yet why I am looking for examples and still reading.
The most obvious case of a circular reference is self-promotion: you need this for linked lists, trees, and many other recursive structures.
, .
, - : (, ) , (, , ..) . , , , , ; , ..
, , Creature-CreatureAI: , , , .
, , . , .
, , . , , ORM .
; , , , . - .
; . , "" "" node , , node .
.
, () , , ... .
, , .
In other cases, this is really necessary. For example, some relationships must be represented in the code as a data structure, and the relationship is reflective.