Java EE - DAO DVO
我见过两种实现 DAO-DVO 设计的方法。
1) DVO 是对象,DAO 是使用工厂实例化的,即 DAO 也是对象 2) DVO 也是对象,但在这种情况下,DAO 是仅包含接受 DVO 执行任务的静态方法的类。
我想知道哪种方式更好且更具可扩展性。
I have seen two ways of implementing DAO-DVO design.
1) DVO are objects and DAOs are instantiated using factories i.e DAOs are also objects
2) DVOs are again objects but in this case, DAOs are classes which contain only static methods which accept DVOs to perform tasks.
I was wondering which way is better and more scalable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如何下载DAO Factory来创建数据库连接?
How to download DAO Factory to create Database Connectivity?
我强烈建议不要使用那么多层,除非它们确实是物理分层的。 例如,如果您有类似富客户端的东西,您需要发送分离的对象来更新 GUI,否则,这是一个痛苦的世界。
I would strongly recommend not using that many layers unless they are really layered physically. eg if you have something like a rich client where you need to send detached objects to update the GUI, otherwise, its a world of pain.
关于可测试性,我建议不要采用第二种方法。 静态方法阻止您通过使用模拟等覆盖协作者来调整类的行为。 正如 Miško Hevery 所说:“静态方法是可测试性的死亡”。
With regards to testability, I'd advise against the second approach. Static methods prevent you from adjusting the class's behaviour by overriding collaborators with mocks and such. As Miško Hevery puts it: "Static Methods are Death to Testability".
尝试 Spring 框架。 DAO 通过依赖注入进行初始化,只是普通的“ole Java 对象”。
然后,DAO 上的方法应该只使用应用程序所有层使用的域对象。
Try the Spring Framework. DAOs are initialized via Dependency Injection and are just plain 'ole Java objects.
Then, the methods on the DAO should just use Domain Objects that are used at all layers of the Application.