I believe I structure my projects like many people do. You have a data layer (DAO's), service layer (services) and presentation layer (Spring MVC, Wicket, ...).
Usually a service starts of being quite simple and 'short'. Gradually however the service must support more and more use cases until after a while it becomes one huge class with many lines and methods and difficult to read and maintain. At that time you can either decide to stick with it or start refactoring which is a cumbersome and 'dangerous' job that can take a lot of work.
I am looking for a solution in how to prevent the need for any future refactoring.
One approach could be splitting up your services in several sub-services and make your original service a service façade. So, for instance, instead of a big UserService you could have a UserServiceFacade which delegates the calls to PasswordService, RegistrationService, ... .
It's not a bad solution I think but I'm not too enthusiastic about it because:
Another solution might be using Business Objects which (in my understanding) can also be seen a subservices but then one per specific UseCase, so you might have BO's like CreateUserBO, CheckPasswordBO, DeleteUserBO, ... .
I'm a bit more enthusiastic about this approach because, in my opnion, it offers quite some advantages:
I do however also see some possible downsides:
The question or rather questions (sorry) are:
I would recommend you to look at this article on Domain Driven Design if your application is anything serious than college assignment. The basic premise is structure everything around your entities and have a strong domain model. Differentiate between services that provide infrastructure related things (like sending email, persisting data) and services that actually do things that are your core business requirments.
I would also suggest to explore Spring Roo - which brings in some revolutionary stuff in as far as strcuturing your layers are concerned like not having to need DAO layers etc.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With