[#6880] improve(core): Refactor EventBus#dispatchEvent
What changes were proposed in this pull request?
Refactor EventBus#dispatchEvent.
By adding the accept(EventVisitor visitor) method to BaseEvent and its subclasses, the handling logic is delegated to the event itself. This allows the EventBus to simply call event.accept(InternalVisitor()), with the event determining how it should be processed.
- Type-safe – Eliminates the need for
instanceofchecks - Clear decoupling – Events are only responsible for invoking
acceptmethod, without knowing the listener implementation - Strong encapsulation – Prevents external misuse by restricting direct access to visitor methods
- Easily extensible – Adding new event types only requires creating new classes and visitXxx() methods, without modifying the dispatch logic
Why are the changes needed?
Fix: #6880
Does this PR introduce any user-facing change?
no
How was this patch tested?
local test.
Hi @FANNG1 , could you please review this PR when you have time? I’d really appreciate your feedback.
There are some benefits, and the con side is this may make the code a little hard to understand and maintain. Is it worth to do the refactor? @jerryshao WDYT?
@FANNG1 Gently ping, should we close this PR?
@FANNG1 Gently ping, should we close this PR?
I am inclined to close the PR.
@FANNG1 Gently ping, should we close this PR?
I am inclined to close the PR.
Close this issue