Best way to develop service layer in java [closed]

2019-04-02 11:39发布

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

2条回答
爷的心禁止访问
2楼-- · 2019-04-02 11:55

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

  • the service layer and the persistence layer are not the same thing. To ease decoupling and testability, I prefer having a pure service layer and a data access layer
  • inheritance is generally not the best way to reuse code. Use a well-design API, and prefer delegation over inheritance.

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

查看更多
疯言疯语
3楼-- · 2019-04-02 12:08

You should consider using some framework, which will help you with routine. E.g. Spring or Java EE. Those frameworks can offer you many built-in solutions like IoC, declarative transactions, declarative security etc.

查看更多
登录 后发表回答