在java中开发服务层的最佳方法 [英] Best way to develop service layer in java

查看:330
本文介绍了在java中开发服务层的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用java为我的应用程序开发服务层。同时服务层也可以暴露给webservice。

I wants to develop service layer for my application using java. At the same time the service layer can also be exposed to webservice also.

我的想法是为数据库操作创建一个通用抽象类,所有其他服务类扩展抽象类,并通过抽象类方法进行数据库操作。

My idea is to create one Generic Abstract Class for database operations , and all other service classes extend that abstract class and do the DB operation through that abstract class methods.

这是一个好主意吗?
请帮助我

Is this a good idea to do it? Please help me

推荐答案

很难说这么少的细节,甚至不知道你会用什么访问数据库(JDBC?JPA?Hibernate?)。但

It's hard to say with so few details, and without even knowing what you'll use to access the database (JDBC? JPA? Hibernate?). But


  • 服务层和持久层不是一回事。为了简化解耦和可测试性,我更喜欢拥有纯服务层和数据访问层

  • 继承通常不是重用代码的最佳方式。使用设计良好的API,而不是委托而不是继承。

另外,不要重新发明轮子。 EJB3,Spring和其他框架可以很好地支持开发服务并将它们作为Web服务公开。

Also, don't reinvent the wheel. EJB3, Spring and other frameworks have good support to develop services and expose them as web services.

这篇关于在java中开发服务层的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆