I'm designing an API that receives several event types all inheriting from a common base class. So lets say EventA and EventB inherit from BaseEvent These events need to go trough several different processors. So I though the visitor pattern would be a good choice here. So the BaseEvent would look something like this:
public class BaseEvent implements Visitable {
void visit(Visitor visitor) {
visitor.visit(this);
}
}
So now I have an API that includes the Visitable and the Visitor types, but they are not really related to the API. the processing is only done on the receiving side.
So I though about defining the API types without the Visitor interfaces and to define new types that include the visitors on the receiver of the events But then I have to translate the API types to the new types and I don't see a way to do it without using instanseof for every event type
Does anyone see a solution for this? Or maybe some other design that can solve the problem?
Thanks
Edit (Adding Some more info): The events just hold information and on the receiver side they need to go through the processors. I currently have 3 types of events (but that is likely to grow), and 2 processors (this can also change but less likely) I wanted to use the visitor pattern cause it forces me to add new methods to the processors when new events are added If I just override the process() method for each type I will only catch errors in runtime when new events are added