Order of behavior selection

1. Behavior selection order

    Since the model itself can define the behavior, the behavior can also be inherited from the descriptor (class), and can also be inherited from other models that are inherited, so how to determine the behavior of a model?

    To get a behavior, it is obtained by the name of the behavior, in the following order:

  1. See if the model itself defines a behavior with the same name.
  2. See if there is a behavior with the same name defined on the immediate descriptor (class).
  3. See if there is a behavior of the same name defined on direct inheritance.
  4. See if the descriptor inherits the behavior of the same name.
  5. See if the successor inherits the behavior of the same name.

    When any of the above nodes are satisfied, the corresponding behavior will be returned, and subsequent nodes will not be acquired.

2. Performance issues

    Since the behavior of obtaining a model requires multiple searches, in order to improve performance, after obtaining an action, the search chain will be cached. When the model in the search chain has not been modified, it will directly return the cached action, otherwise search again.

    If a behavior is not defined, it will return null. The behavior of null will not be cached, so it will always be searched again. To prevent slow performance, when defining classes and interfaces, you should define a Default action.

   

Copyright ©  2007-2019 XWorker.org  版权所有  沪ICP备08000575号