I’m refactoring some code and I want to do something really generic that would help the code in the future for adding features… But I just can’t manage to do it 🙁
Here’s what I want with an example :
I have 3 classes Kitchen, Bedroom, Toilet which are Rooms.
I also have 3 classes called KitchenObject, BedroomObject, ToiletObject which are RoomsObject.
But here’s when it gets worse, I also have 3 enum called KitchenObjectType, BedroomObjectType, ToiletObjectType that differenciates the classes above.
Let’s imagine I want to gather(Type) a specific type of objects.
How can I force all my Rooms to have a gather method that takes in parameter the intended enum ?
Right now, it’s more-or-less how it works, but with 0 interfaces/inheritage etc etc… and the plan is that if I add a new Room, per exemple LivingRoom, I want this class to be forced to implement the gather method with a LivingRoomObjectType that gives LivingRoomObject in return.
Here under is the ideal usage of what I need, thanks a lot in advance !
Bedroom bedroom = bedroomDAO.load();
Kitchen kitchen = kitchenDAO.load();
List<BedroomObject> bedroomObjects = bedroom.gather(BedroomObjectType.CLOTHES) ;
List<KitchenObject> kitchenObjects = kitchen.gather(KitchenObjectType.SPICE);
So I tinkered a with abstract classes/interfaces but I’m not able to create that gather function with a specific RoomObject (I’m obliged to use RoomObject) neither can I put a specific ObjectType as parameter…
Looked into java classes like AbstractList for examples but I’m more lost then ever !