【发布时间】:2019-05-29 11:33:37
【问题描述】:
正如您在示例中看到的,
- 我有 Core 类,用于将共享变量/方法等分配到 mixins 中。
- 用于定义必要方法的抽象类,提供关于 api 的摘要。
- 用于像提供程序一样导入所有内容的主类。
当然没有任何运行时错误。
这种方法的问题,mixin方法不能识别@override注解。
我想为我的包创建精细、干净的结构。对于这种情况,最好的方法是什么?或者我在做什么?
abstract class AbstractCore {
void foo();
void bar();
}
class Core {
var shared;
}
mixin Feature1 on Core {
@override // not recognized by syntax of course
void foo() {
// something with [shared]
}
}
mixin Feature2 on Core {
@override // not recognized
void bar() {
// yet another thing with [shared]
}
}
class Main with Core, Feature1, Feature2 implements AbstractCore {}
你可以接受这样的:
- 核心:ApiBase(用于共享Client对象、常量、保持dispose方法...)
- Feature1:比方说与身份验证相关的 Api 调用
- Feature2:比方说与内容相关的 Api 调用
- 主要:API 提供者。
【问题讨论】: