I know this topic has 2 kinda of duplicates by there where TL;DR; use method override, mine i belive is not that simple.This will be basically a theoritical question i wont link the code cause its just to long.
Imagine that we have 3 different types of emergency centers which all inherit an abstract class which implements an interfaces (FireServiceCenter, MedicalServiceCenter and PoliceServiceCenter)
And 3 types of emergencies which all inherit an abstract class which implements an interface (OrderEmergency, PropertyEmergency, HealthEmergency)
Each of the 3 centers can only take care of 1 type of emergency and there are only 3 centers not more and all are different types, i.e. we can handle all emergencies.
FireServiceCenter - > PropertyEmergency
MedicalServiceCenter - > HealthEmergency
PoliceServiceCenter - >OrderEmergency
The input will be, let's say, 500 different emergencies and just link them to their respective center
How can I accomplish this without using instanceOf?
My first thought was to just add an extra final static field to each center
and emergency class witch I would have called typeOfCenter/typeOfEmergency and add all of the emergencies in 1 collection and then all centers in 1 collection and then just match them together (with 2 for loops: 1 for centers and 1 of emergencies), but I don't know how this is any different frominstanceOf cause i will be using .equals for their fields.