A
Angus Parvis
Hi,
another question: I have some objects, which shall reference each other.
It's a game, and in this game I have planets and players. There's no
planet without a player and no player without a planet. It's essential,
that they both know about each other.
At the moment i'm solving the problem like this:
Player player = new Player();
Planet planet = new Planet(player);
player.setPlanet(planet);
But I don't feel very comfortable about this solution. In my opinion
both Player and Planet should be in a valid state after creation - but
they are not. The user has to know, that the Player.setPlanet()-method
has to be called, to ensure correct behavior.
And what if there are 3 or more objects that have to know about each
other? Does anyone know a good clean and stable approach?
Thanks in advance,
Angus
another question: I have some objects, which shall reference each other.
It's a game, and in this game I have planets and players. There's no
planet without a player and no player without a planet. It's essential,
that they both know about each other.
At the moment i'm solving the problem like this:
Player player = new Player();
Planet planet = new Planet(player);
player.setPlanet(planet);
But I don't feel very comfortable about this solution. In my opinion
both Player and Planet should be in a valid state after creation - but
they are not. The user has to know, that the Player.setPlanet()-method
has to be called, to ensure correct behavior.
And what if there are 3 or more objects that have to know about each
other? Does anyone know a good clean and stable approach?
Thanks in advance,
Angus