| Author |
Spring Multiple Service Design approach
|
Manish Ranch
Greenhorn
Joined: Dec 09, 2011
Posts: 3
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Manish Ranch
Greenhorn
Joined: Dec 09, 2011
Posts: 3
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
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
Joined: Dec 09, 2011
Posts: 3
|
|
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
|
 |
 |
|
|
subject: Spring Multiple Service Design approach
|
|
|