When using P5 with Eclipse, I have to reference the main applets graphical context from some objects of the program (say, in their display() functions). All in all with time it starts looking like this:
- this.parentPlane.parentWorld.parentGame.parentTestProject.line(x, y, xx, yy);
Where
this is an object of class "Ship" which dwells in one of the Planes of the World which in turn is one of the Worlds of the Game which itself is a child of the main TestProject class which extends PApplet and posesses the main graphical context
g.
My question: is this ok that I have references of such length? Is there any other (better) way that programmers would use instead of this? My only guess is to replace multiple lines with this same reference with something like:
- TestProject context = this.parentPlane.parentWorld.parentGame.parentTestProject;
- context.line(x, y, xx, yy);
- context.rect(x, y, xx, yy);
- etc...
1