mardi 28 février 2017

Static classes or instance pointers

Backstory:

Currently I have a series of three classes related to a game. I've previously made games using Unity where you access components such as the camera using functions accessible throughout all code. My current setup, however, relies on instances of each class being sent across the other classes. See the following outtake:

class World{
     *Game game;
     *Camera camera;
};
class Game{
     *Camera camera;
     *World world;
};
class Camera{
     *Game game;
     *World world;
};

Questions:

  • Is this a result of bad design or are there times when a setup like this is justified?

  • Should I rather use static classes over my current setup since it would clarify the code and no more than one instance of each class is ever used?

  • What are the possible downsides of using static classes over instances?

Aucun commentaire:

Enregistrer un commentaire