如何正确使用 ExtensionManager 和 ExtensionHandler 实现 类

How to properly use ExtensionManager and ExtensionHandler implementing classes

My first question is what is motivation behind this aproach if polymorfism is whole paradigm addressing this problem? What are benefits ?

这允许 Broadleaf 生态系统中的多个 "modules"(插件)在运行时(通过注册它们自己)而不是在编译时修改行为。这是一个松散的耦合。此外,如果您需要多次修改代码中的同一位置(此时您需要多重继承)

Secondly if I'm going to use it what is correct way to do that?

根据您所说的,您永远不需要扩展扩展 manager,而只需扩展 handler。然后处理程序应该向管理器注册自己。这是一个例子:

@Component
public class MyInventoryExtensionHandler extends AbstractInventoryServiceExtensionHandler {

    @Resource
    protected InventoryServiceExtensionManager extensionManager;

    @PostConstruct
    public void init() {
         extensionManager.registerHandler(this);
    }

    @Override
    public ExtensionResultStatusType retrieveQuantitiesAvailable(Collection<Sku> skus, Map<String, Object> context, ExtensionResultHolder<Map<Sku, Integer>> result) {
        ...
        ...
        return ExtensionResultStatusType.HANDLED;
    }
}

For example I tried to extend AbstractInventoryServiceExtensionHandler and override methods (because broadleaf 5.0.1 has a bug in InventoryServiceImpl regarding CHECK_QUANTITY InventoryType in retrieveQuantitiesAvailable method)

错误是什么?