gravitino icon indicating copy to clipboard operation
gravitino copied to clipboard

[#6880] improve(core): Refactor EventBus#dispatchEvent

Open Abyss-lord opened this issue 8 months ago • 2 comments

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.

  1. Type-safe – Eliminates the need for instanceof checks
  2. Clear decoupling – Events are only responsible for invoking accept method, without knowing the listener implementation
  3. Strong encapsulation – Prevents external misuse by restricting direct access to visitor methods
  4. 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.

Abyss-lord avatar Apr 10 '25 07:04 Abyss-lord

Hi @FANNG1 , could you please review this PR when you have time? I’d really appreciate your feedback.

Abyss-lord avatar Apr 10 '25 08:04 Abyss-lord

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 avatar Apr 14 '25 09:04 FANNG1

@FANNG1 Gently ping, should we close this PR?

Abyss-lord avatar Jun 12 '25 14:06 Abyss-lord

@FANNG1 Gently ping, should we close this PR?

I am inclined to close the PR.

FANNG1 avatar Jun 13 '25 02:06 FANNG1

@FANNG1 Gently ping, should we close this PR?

I am inclined to close the PR.

Close this issue

Abyss-lord avatar Jun 13 '25 03:06 Abyss-lord