Friday, 16 August 2013

How do I know when to use an enum or a sub-class?

How do I know when to use an enum or a sub-class?

Let's say I am making a game of chess. Would it be more effective to have
a base class of Piece()? With sub-classes for each type of piece.
Or, an enum
enum Piece{
King,
Queen,
Knight,
etc;
}
It also brings me onto a common problem I have when refining data.
GameObjects
Piece extends GameObjects
Should I stop here and declare the objects with their individual properties?
Piece King = new Piece("King",5,10); //just made up values, no significance.
Or refine it further and have:
King extends Piece
and then handle King Pieces in a polymorphic way:
Piece king = new King("King,5,10);
thanks

No comments:

Post a Comment