gpt4 book ai didi

java - 实体和适配器模式

转载 作者:行者123 更新时间:2023-12-02 00:46:53 25 4
gpt4 key购买 nike

我想知道什么是正确的选择:我有一个 eclipse rcp 应用程序,它使用一些 JPA 实体。现在我很想使用适配器模式,它是通过 IAdapterFactory 和 IAdaptable 接口(interface)提供的。据此article我的实体必须实现 IAdaptable 接口(interface),但我想要拥有干净的实体,而且我也不想编写愚蠢的 ContentProvider。我的问题:除了使用 ContentProvider 之外我还有其他选择吗?

最佳答案

Look at this

他们说实现IAdaptable并不是绝对必要的。

也可以这样做

IAdapterManager manager = Platform.getAdapterManager();
... = manager.getAdapter(object, IResource.class);

例如WorkbenchLabelProvider 使用 org.eclipse.ui.internal.util.Util.getAdapter() 检查对象是否为 IAdaptable 稍后使用 IAdapterManager

IAdapterManager 管理 IAdapterFactories。适配器工厂可以使用 registerAdapters 方法以编程方式注册。或者,可以使用 org.eclipse.core.runtime.adapters 扩展点以声明方式注册它们。

关于java - 实体和适配器模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4740925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com