【发布时间】:2016-03-03 20:57:07
【问题描述】:
在 Java 中实现骨架类的正确风格是什么?
我所说的骨架是指提供骨架实用程序代码的类,但需要一个子类来实现某些部分。
在 C++ 中,我只会将纯虚方法添加到类中,但 Java 对接口和类有严格的区分,所以这不是一个选项。
基本上模式应该是这样的:
class Skel {
void body() {
this.action1();
this.action2();
}
};
class UserImpl : extends A {
void action1() {
impl;
}
void action2() {
impl;
}
}
/* ... snip ... */
Skel inst = new UserImpl();
/* ... snip ... */
inst.body();
【问题讨论】:
-
你不是在找抽象类吗?
-
还有 C++?这不是合法的 Java 代码。
标签: java skeleton-code