Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Multiple Service Design approach

 
Manish Ranch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a one question on design. I have an application which actually just have one service layer, but now its becomes so large that it has got more than 2000 lines, so I decided to refactor the service layer into multiple services with one abstract service.
so basically now I have
1. AbstractService
2. Service1
3. Service2
4. Service3

each service extends the abstractservice. each service uses other service method via autowiring. and all the autowiring are declared in abstractservice
like :



Just want to know if that is the good design approach or should I have one service locator , that should gives me one service that I want as I find it hard to test each service layer independently as each is dependent on other?

I will appreciate any of your opinions

-Manish





 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manish welcome to JavaRanch.

I don't really know much details about your implementation, but if to complete one action you need methods from two different classes then that's sort of breaking cohesion and introducing coupling. In that case you've merely split one class into multiple classes which are tightly coupled which doesn't give you much advantage...
 
Manish Ranch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ankit,

Appreciate your reply. You understood my problem correctly. That has introduced tight coupling between services but I have read somewhere its better to refactor service class, if its too long. Thats the reason I did it. Initially I tried refactoring taken out the common code and putting it in helper classes, even then it was too long

Any ideas how to make this service more readable and maintainable.

-Manish
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish if you can find some sort of association between your service tasks, then you should use separate classes for related tasks. That way your individual classes won't be coupled with each other...
 
Manish Ranch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ankit,


Thanks for your reply. I will try to do some sort as association as much I can do. I guess this could only be the best way.


Thanks for your efforts in replying my question. I will mark it as resolved.

-Manish
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic