I am working on making a Pong clone as a practice project. I have a PongStatePongState
class with members like "Ball"Ball
, "Paddle"Paddle
, "Board"Board
and "Score"Score
. I want to structure my code so that each object doesn't have to know how to render itself, but a rendererPaddleRenderer
class will do that. So I also want to create a PongStateRenderer class. The PongStateRendererPongStateRenderer
class, which may use other classes like "PaddleRenderer"PaddleRenderer
, as well.
My question is howHow should the PongStateRendererI let PongStateRenderer
know about the internals of PongStatePongState
so that it can render it? The "Ball"Ball
object in PongStatePongState
know's it's own position and size, does that mean "Ball"Ball
has to be a public member variable so that PongStateRendererPongStateRenderer
can also know the position? Or, or is there a better way to do this without totally breaking encapsulation? Or isPerhaps my architecture is totally wrong, and I should use a different method?
I'm working in C# as it says in the tag but a general answer that applies to many languages could also be helpful.