vendredi 27 septembre 2019

Subclasses or Additional fields in the base class for Identification

I am developing a game which has all sorts of Entities. An Entity can have name, image, xposition, yposition etc. Also, there can many types of entities such as:

  • The entity may or may not be a coin (for point collection) - star
  • The entity may or may not allow the ball to pass through - Permeability
  • The Entity may or may not be throne (which will burst the ball) - Enemy

Now if I need to check if the ball is colliding with the entity is permeable or not, if it is a coin or not , if it is an Enemy or not.

In this kind of situation, is it better to have a just one class with all the above-mentioned fields (name, xposition, yposition..) + boolean fields such as isCoin, isPermeable, isEnemy?

OR

A subclass derived from base class Entity for Coin, Permeability and Enemy?

Note - At this stage, I can't think of any additional thing the coin subclass, or the enemy subclass will be doing. In a sense, it is more for identification, not so much for adding extra functionality to the subclass.

Thanks

Aucun commentaire:

Enregistrer un commentaire