Skip to content

Key Concept —— Ability

Ryu Xin edited this page Sep 27, 2022 · 8 revisions

Concept introduction

In the Lattice framework, there is a term called "Ability". Here, I make my understanding of this term.

"The Spring and Autumn Annals": "The people want to be rewarded when they advance, and they are afraid of their sins when they retreat, and they know their insufficiency!"

Fang Ji's "Autumn in the Three Gorges" II: "The Yangtze River contains infinitely rich water energy; the Three Gorges have formed a natural water conservancy hub. This may become a huge capacity in my country's construction."

Mao Zedong wrote in "Commemorating Bethune": "A person has great or small ability, but as long as he has this spirit, he is a noble person."

Leaders mentioned in the platform launch meeting: "A platform has large and small capabilities, but as long as the structure is excellent and continuous improvement is made, it is a promising platform."

As can be seen from the above famous remarks, ability is a description of a set of behaviors displayed by specific carriers such as people and objects in certain scenarios.

For example, when we talk about the ability carrier of "people", we will say:

  • Humans have the ability to change the world
  • Humans have the ability to reproduce
  • People have the ability to bullshit
  • Cross talk actors (examples of people) have the ability to talk, learn and sing
  • Athletes (instances of people) have the ability to run and jump
  • ......

Characteristics of Ability

If we further subdivide, the human carrier is composed of head, trunk, limbs, menstrual blood, veins and various internal organs. These different components can also be used as a carrier to provide some more subdivided and specific capabilities. For example, the carrier of the hand, although he does not have the ability to reproduce offspring. But the ability of the hand is: the ability to bend, the ability to carry weight. The behavior of bending the hand includes bending the wrist and bending the fingers, and the weight-bearing behavior of the hand can include weight-bearing in the palm and fingers. Although the ability of the hand and its behavior are very limited, they can work together to complete push-ups, and finally support and realize the realization of the more important ability of human reproduction.

So, capabilities are aggregatable

When it comes to the behavior of the ability, the behavior should be extensible, and the extended behavior can do more things that could not be done before. Such as the act of scratching. In fact, it is quite simple. The basic tickling action is to scratch with your hands, and you can scratch where you can. But what if you can't catch it? You have at least two options:

  1. Change the behavior, use "rub" instead, find a place to rub hard on the itching..
  2. I still use the behavior of "scratching", but I have to expand my hand and use "don't ask for help" to complete the "scratch" on the itching.

So, the behavior of capabilities is extensible

The capabilities of the hand and its behavior just mentioned are both native and innate. However, we can add some abilities that we do not have by adding plug-ins to people. For example, by equipping the eyes with night vision glasses, a person can have night vision behavior like a cat. The carrier of night vision glasses is the eyes, which expands the behavior of seeing, so that people have the ability of night vision.

Therefore, some abilities are not necessarily native, but can be superimposed through tools

Sometimes, you can be really good at something. For example, you can sing well, dance well, and play table tennis well. However, in the programmer's world, you said, everyone may not care and remember. But if you don't say it, you are very likely to lose a good opportunity to sing with the goddess.

So, capabilities must be presentable, at least for a specific scene/view

If you can understand the above concept, then look back at the definition of capability interface in Lattice.

In Lattice, we define the capability interface IAbility:

public interface IAbility<BusinessExt extends IBusinessExt> {

    /**
     * @return current ability's unique code.
     */
    String getCode();

    /**
     * @return current ability's instance unique code.
     */
    String getInstanceCode();


    AbilityContext getContext();

    /**
     * Whether current ability support current bizObject
     *
     * @return default return true.
     */
    boolean supportChecking();


    /**
     * Whether current ability support customization from plugin's extension realization.
     *
     * @return true or false.
     */
    boolean supportCustomization();

    /**
     * Whether current ability invoke getDefaultRealization() if the extension
     * realizaiton not found in the Plugin.
     *
     * @return true or false.
     */
    boolean hasDefaultExtension();


    /**
     * get the extension points' realization by business code.
     *
     * @return the ExtensionPoints realization.
     */
    IBusinessExt getDefaultRealization();

    /**
     * Execute the extension's customization.
     *
     * @param extCode  the code of extension point.
     * @param callback callback of the function.
     * @param reducer  The multi-result reduce policy.
     * @return the result of extension customization.
     */
    <T, R> R reduceExecute(String extCode, ExtensionCallback<BusinessExt, T> callback,
                           @Nonnull Reducer<T, R> reducer);
}

There are two key methods in the Iability capability, one is supportChecking. It is used to check whether this ability is supported for a specific carrier under a specific business constraint (AbilityContext)? Simple analogy:

  • Look" this behavior, ask the "hand" for the carrier, and you should get a result of false
  • "Look" behavior to ask "eyes", should get the result of true

Another method is reduceExecute() to invoke custom implementation of the behavior. for example:

  • Obtaining EmptyEyeExtension for the eye carrier means that there is no available behavior, such as blind people
  • What is taken out for the eye carrier is the basic implementation of NormalEyeExtension, then the basic viewing behavior can be completed.
  • The enhanced version EnhancedEyeExtension is taken out for the eye carrier, then the night vision behavior can be completed.

For an example of how to specifically define a ability, you can refer to: Quickstart Quide


中文版:https://www.ryu.xin/2021/08/25/lattice-concept-ability/