Freeze Business Logic Layer.
We regularly work on three-layer architecture for application development and always use some standard data layer and UI layer guidelines for design but what we always ignore is business logic layer. The reason behind maybe we are not comfortable in designing something which has no limits and no boundaries defined. If I share my experience; whenever we have tried to freeze our business logic, ironically, we felt a need to extend it to accommodate new requirements or sometimes for better optimization. Though, I have no correct answer for achieving best design for business logic layer but we can explore it a bit.
What is a Business Logic Layer?
One of the architecture followed in application development environment is Layer Architecture.With this architecture, Applications is trusted with different layers responsible for performing a designated role. It improves isolation of concerns. Mainly Layers are divided into
- the Data Access layer
- the Business Logic layer
- the Graphical User Interface layer
For more information on architecture,read this article.
The business layer contains business entities. A business entity is a type of business component that represents a domain model object used within the service boundary. Typically, business entities represent real-world objects, such as customers and orders. It contains all the business rules that are applied to data exchange process which happens between the presentation layer and the Data access layer.
Business rules describe the operations, definitions and constraints that apply to a user/community/organization. To understand it, check these examples
- A customer is entitled for bonus offers if he has done a purchase of minimum limit.
- User is not allowed to register if it does not adhere to specific guidelines.
- Employer can enlist constraints and conditions on employees of the organization.
- Legal rules
Benefits of Business Logic Layer
- Flexibility: Business Logic Layer which provides decoupling from the application and allows the flexibility to build other applications on top of it in the future.
- Maintainability: Business Logic Layer optimizes the way that the application works when deployed in different ways, and provides a clear delineation between locations where certain technology or design decisions must be made.
- Reusability: Business Logic Layer follows components based architecture and can be reused in different business models.Each logical layer contains a number of discrete component types grouped into sub layers, with each sub layer performing a specific type of task
- Scalability: Business Logic Layer can perform well in extended conditions.
Guidelines for Business Logic Layer Design
- Loose coupling is the key: Different patterns are available to implement loose coupling like Factory Design Pattern, Singleton Pattern.The business layer should know only about the layer below (the data access layer), and not the layer above (the presentation layer or external applications that access the business layer directly).
- It is always a good idea to use a separate business layer where possible to improve the maintainability of your application.
- Identify the responsibilities of your business layer. Use a business layer for processing complex business rules, transforming data, applying policies, and for validation.
- Do not mix different types of components in your business layer.Use a business layer to decouple business logic from presentation and data access code, and to simplify the testing of business logic
- Reuse common business logic. Use a business layer to centralize common business logic functions and promote reuse.
- Identify the consumers of your business layer. This will help to determine how you expose your business layer. For example, if your business layer will be used by your presentation layer and by an external application, you may choose to expose your business layer through a service.
- Reduce round trips when accessing a remote business layer. If you are using a message-based interface, consider using coarse-grained packages for data, such as Data Transfer Objects. In addition, consider implementing a remote façade for the business layer interface.
There is no exact understanding about design of Business Logic Layer which can be taught but people can only learn through their experience. I really appreciate, if people can contribute their experience to improve this article.