16th
AUG

Degin and Review of Business Layers - Quick Tips

Posted by Sambeet Patra under Software Architecture

In a typical 3-tier application, designing the business layer is a key factor in making the application robust and maintainable. Here are some tips on designing the business layer in a Multi Layered Architecture. These tips can be put into practice while designing / developing / reviewing the business layer.

1. Identify the responsibility and boundaries of the layer. In a typical 3 tier [data-business-presentation] application, a business layer should not expose functions specific to a presentation component. Similarly, the business layers should not even know the details on data source. One way to achieve this is to consider a layer as the end point of the application and identify the functionalities without thinking of the consumers of the current layer.

2. Develop apis that represent wholesome logical functionalities. For example, if you are writing a banking application, there should be one api in the business layer to transfer money. The user of the layer should not have to call multiple apis to first withdraw money from one account and then deposit in the other account. If you rely on the users of a layer to call multiple apis to execute a business process, you are effectively not abstracting the functionality.

3. Implement data validation in the business layer. Many people leave the data validation responsibility to the presentation layer and make an assumption that the business layer will get the right data all the time. But in reality, the presentation layer changes most often and the validation routines may not be full proof all the time. So, it is a much more reliable practice to keep the business layers self sufficient in terms of data validation. Extending this argument, during the course of the project lifecycle, make it a point to implement unit testing for the business layer apis.

4. It is imperative that the detailed implementation of the business layer be abstracted from the users. Publish interfaces that contain business api definitions. Provide well defined options to obtain implementation of the interface [a great example is the factory pattern]. Apart from these, make sure all other utility classes are made internal to the business layer.

5. Always think of scalability while designing a business layer. When implementing query methods, make sure the methods implement paging to limit the amount of data retrieved. Also, the methods should be state-less.

Leave a Reply