Reputation: 275
I am trying to develop some RESTful web services which have to access some backend system for data. These backend sources can be any one of the folowing :
Database through JDBC
ERP, communicates through SOAP
Another J2EE application, communicating through SOAP or maybe REST.
What best can I do at my level to have a loose coupling between my business layer and the DAO ? IS there some design pattern which may help me ?
Thanks a lot for the help !!
Upvotes: 0
Views: 1532
Reputation: 1099
Hope this helps:
Layer your system: as you mention in your answer, always split bz logic from the data access logic. I would recommend to implement different layers in different binary modules, this will give you the flexibility to deploy different layers in different tiers (if you really need it).
Repository pattern: the business layer has abstract definitions of how to perform data access operations with certain entities in your bz logic. The methods in the repositories always use entities defined in your bz logic as parameters (the repositories always "talk" in the the bz language ). Once the repository interfaces are defined in the bz layer, you implement them in a separate layer: the data access layer.
Dependency injection: in the application layer (GUI, application server, ...), in the initialization logic (bootstrapping) you can use a dependency container to inject the repository implementations (the ones defined in the data access layer) in your bz logic. There a lot of open source frameworks with dependency injection containers.
With these 3 patterns, you can separate the DA logic from your bz logic.
Note that this is a very short answer, I would recomend you to take some time and read the following books:
Thanks,
Juanjo
Upvotes: 2
Reputation:
I hope I've understood your question correctly.
I'm working on an application at the moment which uses JAX-WS RESTful web services to access data. The data can come from a variety of different sources (two different databases and a Lucene index in our case).
I think, without knowing the specifics of your situation, I can only recommend the typical approach we use:
Although it's an old book, most of this info is in Expert One-on-One J2EE Design and Development. But I'd say these are standard Enterprise Java best practices.
Upvotes: 0