有人认识所附类图中的任何模式/反模式吗?

发布于 2024-08-16 12:44:46 字数 268 浏览 4 评论 0原文

替代文本 http://img8.imageshack.us/img8/8558/classdiagram.png< /a>

简短描述:我怀疑 AbstractCrudDaoImpl 实现从同一父级 (ReadOnlyDao) 继承的接口和抽象类是否正常。

alt text http://img8.imageshack.us/img8/8558/classdiagram.png

Short description: I have a doubt whether it's normal that AbstractCrudDaoImpl implements both interface and abstract class which are inherited from the same parent (ReadOnlyDao).

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

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

发布评论

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

评论(5

泼猴你往哪里跑 2024-08-23 12:44:47

我对 ReadOnlyDao 这个名称持异议 - 它意味着任何实现它的东西也是只读的,这显然是不正确的。

我建议将其更改为ReadableDaoAbstractReadableDaoImpl 也是如此。

I would take exception to the name ReadOnlyDao - it implies that anything that implements it is also read only, which is clearly untrue.

I suggest changing it to ReadableDao. Ditto for AbstractReadableDaoImpl.

凉宸 2024-08-23 12:44:47

您可以将这个问题一分为二:

  • 从另一个接口派生一个接口是否正常且有意义?
  • 同时拥有一个抽象类和一个模拟相同概念的接口是正常的吗?

第一个问题很容易回答:是的,当您有一些类只需要“核心”接口,而其他类则处理更丰富的接口时,这是有意义的。

我之前处理过的另一个问题这里

You could split this question into two:

  • Is it normal and meaningful to have one inteface that derives from another interface?
  • Is it normal to have both an abstract class and an interface that models the same concept?

The first question is easy to answer: yes, this makes sense in situations where you have some classes that only requires the 'core' interface, but other classes that deal with the richer interface.

The other question I've previously dealt with here.

挽心 2024-08-23 12:44:47

这个设计对我来说似乎非常合理。

通过查看您的类图,我能够清楚地了解每个参与者。我认为这是一个好兆头——这意味着角色之间有明确的分离。

事实上,CrudDao 扩展了 ReadOnlyDao 对我来说非常有意义。读写操作是只读操作的超集;如果您可以使用只读接口执行某些操作,那么您也应该可以使用读写接口执行此操作 - 这正是继承所实现的目标。

The design seems very reasonable to me.

By looking at your class diagram, I was able to get a clear idea about each participant. I think that's a good sign - it means there's a clear separation of roles.

The fact that CrudDao extends ReadOnlyDao makes perfect sense to me. Read-write operations are a superset of read-only operations; if you can do something with a read-only interface, you should be able to do it with a read-write interface as well - which is exactly what inheritance achieves.

夜血缘 2024-08-23 12:44:47

看起来很奇怪。 CrudDao 应该访问 ReadOnlyDao 而不是 AbstractReadOnlyDao 吗?起初,AbstractReadOnlyDao 访问 AbstractReadOnlyDaoImpl 看起来很奇怪,但第二次看似乎没问题。

seems weird. Should CrudDao access ReadOnlyDao instead of AbstractReadOnlyDao? At first it seemed weird AbstractReadOnlyDao is accessing AbstractReadOnlyDaoImpl but on second look it seems ok.

堇年纸鸢 2024-08-23 12:44:46

除非您在 AbsractReadOnlyDaoImpl 中定义了一些不在 ReadOnlyDao 接口中的特殊方法,否则该特定继承几乎毫无用处。

否则,看起来不错。

Unless you have some special method defined in AbsractReadOnlyDaoImpl which is not in the ReadOnlyDao interface, that specific inheritance is pretty much useless.

Otherwise, looks fine.

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