Java Swing:实现 TableModel 还是扩展 AbstractTableModel?

发布于 2024-08-31 14:12:22 字数 56 浏览 13 评论 0原文

我什么时候应该实现 TableModel,什么时候应该扩展 AbstractTableModel?

When should I rather implement TableModel and when should I extend AbstractTableModel?

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

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

发布评论

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

评论(3

依 靠 2024-09-07 14:12:22

我应该什么时候实现 TableModel

当您需要表模型的完整干净的实现和/或您必须提供模型本质上尚不存在或不适合的东西时。

我什么时候应该扩展 AbstractTableModel?

当您可以重用抽象类提供的现有结构和方法和/或者您可以更轻松地实现它时。

我们的想法是,如果你可以重复使用它,那就这样做。如果做不到,请从头开始实施。

通过继承 AbstractTableModel,您无论如何都将实现 TableModel 接口,而且会更容易。

When should I rather implement TableModel

When you need a complete clean sheet implementation of the table model and/or you have to provide something that by the nature of your model doesn't exists yet or doesn't fit.

and when should I extend AbstractTableModel?

When you can reuse the existing structure and methods provided by the abstract class and/or it would easier for you to implement it.

The idea is, if you can re-use it, do so. If you can't, implement from scratch.

By inheriting AbstractTableModel you'll be imlementing the TableModel interface anyway, it just will be easier.

陌上芳菲 2024-09-07 14:12:22

AbstractTableModel 具有处理 TableModelListeners 的实现,包括触发 TableModelEvent。如果你想自己处理这个问题,那么确实没有理由延长。在该代码之外,除了对接口中声明的方法进行存根之外,其他代码不会添加任何好处。

AbstractTableModel has implementation for the handling of TableModelListeners, including the firing of TableModelEvents. If you want to handle that yourself, then there really is no reason to extend. Outside of that code, the other code doesnt add any benefit other than the stubbing out of methods declared in the interface.

嗫嚅 2024-09-07 14:12:22

AbstractTableModel 为 TableModel 中定义的许多方法提供默认实现。如果您不需要任何自定义行为,那么您可以简单地扩展 AbstractTableModel。另外,如果您的模型已经扩展了不同的基类,那么仅实现 TableModel 就合适了。

AbstractTableModel provides default implementations for many of the methods defined in TableModel. If you don't need any custom behavior, then you can simply extend AbstractTableModel. Also, if your model already extends a different base class, then it would be appropriate just to implement TableModel.

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