I am implementing a module as per layered architecture. It will have a presentation layer, service layer, a business layer and a DAO layer. As per layered architecture guidelines, the communication flow should be top to bottom. Similarly, the dependency should also be top to bottom i.e. presentation layer - uses -> service layer - uses -> business layer - uses -> DAO layer. i.e. business layer should not depend on service layer and likewise.
Question 1:
What should be the inputs to each layer? Since, the service layer is called from presentation layer, should the service layer accept UI bean as the input? or Service Bean as the input ? Same for business and DAO layers.
Question 2:
Should the DAO layer be per table or can it handle multiple tables (all owned by a single module) ? The data of my module gets stored in multiple tables. Since all these tables are owned by a single module, i think it makes sense to have a single DAO layer which abstracts the multi-table storage of the data from upper layers. Also, if different implementations of a DAO layer needs to be plugged (database storage, SVN storage etc), it makes sense to have a single implementation plugged (which handles all data). Also, multiple table DAO would be performance efficient in terms of fetching data ( a single join query would suffice )
Question 3:
If multiple table DAO design is considered, then the input to the DAO layer would be business bean. It is the responsibility of the DAO layer to convert the business bean to multiple DB beans each representing a table and handling the persistence. But this would not be compliant with the layered architecture where it says that layers should be isolated and any layer should not depend on its upper layer. In this case, the input to DAO layer is business bean (not DB bean) and the conversion from business bean to DB beans and vice-versa is the responsibility of the DAO layer which means it knows how to convert a business bean to DB bean and vice-versa.
Can someone please clarify on the above? What should be the proper way to implement such a module? Is the current implementation as per guidelines? A proper explanation would help a lot. Thanks!
The current implementation I have is
Presentation layer: converts UI bean to service bean and passes it to Service layer.
Service layer: converts service bean to business bean and passes it to Business layer. Also orchestrates calls between various dependent services. Handles transaction boundary. Returns service bean to presentation layer.
Business layer: passes business bean to DAO layer. Returns service bean to service layer
DAO layer: Converts business bean to DB beans and vice-versa. Returns business bean to business layer.