I would like to generalise some code, which implements event handling in a naive way. I have multiple types of events, all share the same base attributes along with attributes that are unique to each type. The events are coming in in a Json format with an attribute that denotes their type. for example :
{id:1, baseAttribute1:X1, baseAttribute2:Y1, type:eventA, eventAattribute1:Z, eventAattribute2:Q}
{id:2, baseAttribute1:X2, baseAttribute2:Y2, type:eventB, eventBattribute1:ZZ, eventBattribute2:QQ}
I am trying to write something generic that will let me implement common handling seperately from the specific one but if i use some base object BaseEvent that eventA and eventB extend from - then, in a factory method for example, i am losing the type of the event and cannot forward it to the correct call so i can't add doStuff(EventA a) and doStuff(EventB b) because the object is of type BaseEvent.