I'm writing a card/ board game in Java. Since the game has lots of cards that interact in different ways, my Player class has become sort of bloated with all these different fields used for keeping track of data that specific cards need. However, not every card is used in every game, so many of these fields are not used. Instead of having several fields that probably won't be used a majority of the time, I was thinking of writing sort of a field map class that could dynamically "create" fields when they were needed. If one type of card required each player to store some data in a List, it could just create one and store it in that player's field map. It could get a little messy, though: what types of keys should I use? Strings? Just plain Objects? And the type of data won't always be a List, so it would probably have to be Map<String, Object>
, and I would have to put in casts. Should the keys be their own class whose identity is based on a String name, but also contain a Class<?>
field, so that it could cast the result for me?
I kind of like this idea, since it means I don't have to mess with the Player class every time I make a new card, but it also seems kind of inefficient and inelegant. Is this a terrible idea?