我来自 REST API 领域,其中 Swagger 等设计和文档工具非常有用且受欢迎。现在我开始研究 MQTT 应用程序,我想在设计、记录和测试主题及其有效负载时采用类似的方法。MQTT 是否也存在类似的工具?
我有一个实体的类层次结构,并希望在Java中为它们创建服务接口的层次结构.然后,UI组件应通过接口访问与实体相关的服务:
class BaseEntity { }
class Fruit extends BaseEntity { }
class Banana extends Fruit { }
class Apple extends Fruit { }
Run Code Online (Sandbox Code Playgroud)
UI组件(在稍微不同的上下文中的多个位置重用)需要通过接口FruitService访问Fruit服务,并且我想在运行时期间确定这将是BananaService或AppleService服务接口.我认为使用泛型这很简单:
interface Service<T extends BaseEntity>
{
List<T> getAll();
void save (T object);
void delete (T object);
}
// More strict interface only allowed for fruits. Referenced by UI component
interface FruitService<F extends Fruit> extends Service<Fruit> {}
// Interface only allowed for bananas
interface BananaService extends FruitService<Banana> {}
class BananaServiceImpl implements BananaService
{
// Compiler error here because …
Run Code Online (Sandbox Code Playgroud)