Why can't a dispatcher see a private handler method in a superclass?

← Dispatcher Validation · Ref: Q849

When a subclass has a dispatcher, it searches the superclass for matching handler methods. Private methods in the superclass are invisible. Use protected instead.

See Q616 for dispatcher ambiguity. See Q621 for dispatch rules.

Example

#!ek9
defines module qa.dispatcher.private.super

  defines class

    BaseHandler as open

      protected process()
        -> input as Integer
        require input?

      default operator ?

    SubDispatcher extends BaseHandler

      process() as dispatcher
        -> input as Any
        require input?

      runDemo()
        this.process("42")

      default operator ?

  defines function

    DispatcherDemo()
      handler <- SubDispatcher()
      handler.runDemo()
      require handler?

Common mistakes

E05180 — Private methods in a superclass are invisible to subclass dispatchers. Use protected. See ek9 -h E05180 for details.

Incorrect:

      private process()
        -> input as Integer
        require input?

Correct:

      protected process()
        -> input as Integer
        require input?
Other ways to ask this
  • What triggers E05180 DISPATCHER_PRIVATE_IN_SUPER?
  • Why must dispatcher handler methods be protected or public?
  • How do I fix private dispatcher handler visibility?

Coming from another language?

Java: Visitor pattern requires public. C#: dynamic dispatch ignores private. EK9: compile-time error if dispatcher handler is private in super.

Keywords: E05180, dispatcher, handler, private, protected, super