I am trying to create a Kit system, let me explain. So players are able to redeem kits(rewards). I created the class Kit
as an abstract class and several other subclasses, such as WaterKit
, FireKit
, EarthKit
, etc...
My goal is that when a player types or does a specific action if will trigger a giveKit()
method. This method will create an object, corresponding the kit they selected. So lets say they decided to redeem the water kit, then it will run the giveKit()
and create a WaterKit
object.
The way I was thinking to accomplish this was to create a HashMap
with a key of a String
(the kit name) and the value would be its respective kit object, for example WaterKit
. The only problem with is that I don't want to instantiate the Kit
objects when added to the HashMap
, because the Kit
objects take parameters regarding Player information, which I can't provide at the moment I load the HashMap
. Every kit parameters change depending on the player that triggered the giveKit()
, that is why I can't instantiate the Kit object when added to the HashMap
. The HashMap
is meant to run as a reference on what object to create, so it would kind of be like this:
// Player triggers giveKit(), they would specify which kit they want (in a String)
// map.get(playerResponse) <--- that would return a Kit object and then I need to instantiate that object
So my question is how would you guys approach this issue? I am a bit confused as to how to solve it.