简体   繁体   English

如何组织接口和类

[英]how to organize interfaces and classes

I know this question has been asked and answered many times, but I am still asking the same question again... 我知道这个问题已经被问过很多次,但我仍然在问同样的问题...

I have started working on a travelling application and for which currently I am working on creating on the creation of the underlying DAO so I am planning to create a generic DAO, its implementation and again an interface for each entity class. 我已经开始开发一个旅行应用程序,并且目前正在为基础DAO的创建而工作,因此我计划创建一个通用DAO,其实现以及每个实体类的接口。

My query is what is the best way to organise all these interfaces as well as their Implementation. 我的查询是组织所有这些接口及其实现的最佳方法是什么。

Thanks in advance 提前致谢

If I understand the question correctly your looking for suggestions on organising your packages? 如果我对问题的理解正确,那么您是否在寻找有关整理包裹的建议?

I'd split then between. 然后我会分开。 com.yyy.zzzz.dao.interfaces and com.yyy.zzzz.dao.impl com.yyy.zzzz.dao.interfaces和com.yyy.zzzz.dao.impl

You're the only one who can take decisions on how your application should be organized. 您是唯一可以决定应如何组织应用程序的人。 You can, of course, follow some recommandations such as the Java Naming Convention for packages, or even try to split your packages for each tier implied in your application; 当然,您可以遵循一些建议,例如对程序包的Java命名约定,甚至可以尝试为应用程序中隐含的每一层拆分程序包。 but in the end, you have to choose for yourself. 但最后,您必须自己选择。

@Kevin D's solution is correct, you could use the com.company.project.dao.interfaces (I wouldn't use interfaces as it's a plural and I avoid plural in package names, but again it depends on you) and com.company.project.dao.impl or you could use packages to split different implementations. @Kevin D的解决方案是正确的,您可以使用com.company.project.dao.interfaces (我不会使用interfaces因为它是复数形式,并且在包名中避免使用复数形式,但同样取决于您)和com.company .project.dao.impl或您可以使用软件包拆分不同的实现。 It's as you want. 随你所愿。 And no one should tell you how to split your own application (except your team). 而且没有人应该告诉您如何拆分自己的应用程序(团队除外)。

The only (but still facultative) rule I would tell you to follow is "Have coherent names". 我要告诉您的唯一(但仍然很容易)规则是“具有连贯的名称”。
That means choose your project convention, but stick to it, and of course the names you choose for your packages (but it also applies on classes, variables) must represent their content (but I suppose this is common sense). 这意味着要选择项目约定,但要遵守约定,当然,为包选择的名称(但也适用于类,变量)必须表示其内容(但我想这是常识)。

On another note, I don't know the context of your work, but you should really read Adam bien's Weblog , you'll see some articles on best practices regarding DAO and "default implementation", maybe it will concern your project. 另一方面,我不了解您的工作背景,但是您应该真正阅读Adam bien的Weblog ,您会看到一些有关DAO和“默认实现”的最佳实践的文章,也许它将与您的项目有关。


Resources : 资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM