有人认识所附类图中的任何模式/反模式吗?
替代文本 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我对 ReadOnlyDao 这个名称持异议 - 它意味着任何实现它的东西也是只读的,这显然是不正确的。
我建议将其更改为ReadableDao。 AbstractReadableDaoImpl 也是如此。
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.
您可以将这个问题一分为二:
第一个问题很容易回答:是的,当您有一些类只需要“核心”接口,而其他类则处理更丰富的接口时,这是有意义的。
我之前处理过的另一个问题这里。
You could split this question into two:
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.
这个设计对我来说似乎非常合理。
通过查看您的类图,我能够清楚地了解每个参与者。我认为这是一个好兆头——这意味着角色之间有明确的分离。
事实上,
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
extendsReadOnlyDao
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.看起来很奇怪。 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.
除非您在
AbsractReadOnlyDaoImpl
中定义了一些不在ReadOnlyDao
接口中的特殊方法,否则该特定继承几乎毫无用处。否则,看起来不错。
Unless you have some special method defined in
AbsractReadOnlyDaoImpl
which is not in theReadOnlyDao
interface, that specific inheritance is pretty much useless.Otherwise, looks fine.