10 个 Java 类层次结构会太多吗?

发布于 2024-11-16 19:11:05 字数 345 浏览 3 评论 0原文

我开发了一个插件加载机制,由于插件层次结构设计,主要是抽象级编程,并且尽可能少地进行高级编程,最顶层插件的插件类层次结构可能达到 八。

我已经加载了数十个插件来延长加载时间,而且似乎加载得很好,所以我想知道除了“继承与组合”之外,继承设计还有哪些不好的副作用强>”设计问题,例如加载或运行时的性能问题。

我想补充一点,这不是插件模型设计问题,这是插件模型的应用程序设计问题,应用程序是否应该知道其所有插件?或者应用程序是否应该定义可能有自己的插件但主应用程序不会意识到它们的插件。该设计适合我,它节省了我的编码时间,问题是它在运行时的表现如何?

提前致谢,

亚当·泽哈维。

I've developed a plugin loading mechanizem, and as a result of the plugins hierarchy design, to be mostly abstract level programming, and with as least high level programming as possible, the plugin class hierarchy of the top most plugins may reach eight.

I've been loading tens of plugins to stretch the loading time, and it seem to load quite OK, so I'm wondering what are the bad side effect of the inheritance design, aside of the "inheritance vs composition" design issues, things like performance issues, in loading, or run-time.

I would add and say, this is not a plugin model design issue, this is application design issue over the plugin model, should the application know all of its plugins? or should the application define plugins which may have their own plugins that the main application would not be aware of them. The design works for me, and it saves me tones of coding time, the question is how would it behave in run-time?

Thanks in advance,

Adam Zehavi.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贩梦商人 2024-11-23 19:11:05

我认为深层层次结构的问题与性能没有太大关系。
更多的是关于代码的可维护性。无论如何,如果您觉得需要如此深的层次结构,请使用它,或发布更多详细信息。

当然,你必须注意你正在做的事情。例如:

public someClassDeepLevel0{ public void foo(){do something}}
.....
public someClassDeepLevel10 extends someClassDeepLevel9{
public void foo(){
 //do something
 super.foo();
}
}

对 foo() 的调用次数与层次结构的深度成正比。如果你正在做这样的事情,那么性能可能会非常重要。

I think that the problem with a deep hierarchy isn't so much related to perforfance.
It's more about maintainability of your code. Anyway if you feel to need such a deep hierarchy use it, or post more details.

Of course you have to pay attention to what you are doing. For example:

public someClassDeepLevel0{ public void foo(){do something}}
.....
public someClassDeepLevel10 extends someClassDeepLevel9{
public void foo(){
 //do something
 super.foo();
}
}

Number of calls to foo() is proportional to how much is deep your hierarchy. If you are doing things like that, then performance could be quite relevant.

海之角 2024-11-23 19:11:05

一般来说,不用担心数字。担心设计。如果设计规定了很深的层次结构,那就这样吧。如果你更看重数字而不是设计,也许你就不应该进行设计。

In general, don't worry about the numbers. Worry about the design. If the design dictates a deep hierarchy, then so be it. If you value the numbers over the design, maybe you shouldn't be designing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文