Circular reference fix?
Posted
by SXMC
on Stack Overflow
See other posts from Stack Overflow
or by SXMC
Published on 2010-04-29T15:16:29Z
Indexed on
2010/04/30
0:57 UTC
Read the original article
Hit count: 416
pascal
Hi!
I have a Player class in a separate unit as follows:
TPlayer = class
private
...
FWorld: TWorld;
...
public
...
end;
I also have a World class in a separate unit as follows:
TWorld = class
private
...
FPlayer: TPlayer;
...
public
...
end;
I have done it this way so that the Player can get data from the world via FWorld, and so that the other objects in the world can get the player data in a similar manner.
As you can see this results in a circular reference (and therefore does not work). I have read that this implies bad code design, but I just can't think of any better other way. What could be a better way to do it?
Cheers!
© Stack Overflow or respective owner