Reputation: 710
Let's say I am making a video game. The player has an X and a Y coordinate, and these values are members of the Player
object. Let us also assume I am using the hypothetical GAME-X
game engine, which renders each object using the GX_x
and GX_y
values.
If I want to separate the domain (Player
) from the view (GAME-X
), it is my understanding that the player should have its own X
and Y
coordinates which are manipulated independently, and the GX_x
and GX_y
simply "listen" to the player's current coordinates. Doing this would allow me to, for example, choose a new game engine while leaving the domain layer untouched. It also means that the game can essentially run on a strictly domain level.
Is this a good design strategy? If not, why? If so, what is the real name for this strategy and how can I improve upon on it throughout my system?
Upvotes: 3
Views: 468
Reputation: 8928
player should have its own X and Y coordinates which are manipulated independently, and the GX_x and GX_y simply "listen" to the player's current coordinates.
That's correct strategy. Since GX_x
, GX_y
are presentation level and can be device / resolution / engine specific.
Consider 2 phones with 480*320
and 960*640
resolutions. x
,y
in your model should be the same (the same code running in both phones) whereas GX_x
and GX_y
will be different on both devices.
It is Model View Controller pattern you're talking about.
choose a new game engine while leaving the domain layer untouched. It also means that the game can essentially run on a strictly domain level.
These are advantages and reasons for the pattern to be used.
Upvotes: 3