dimanche 17 novembre 2013

JAVA application design principles



Purpose of this guide

This guide is intended to give the principles for the application design. They should be implemented as a good practice.

Layering

When layering an application, you should consider:
-          Action layer for processing data significant regarding to the business
-          Model interface for carrying data significant to the business
-          Transverse component for processing data that are not significant for the business
An application shall have three important action layer
-          Data
-          Services
-          Exposure : HMI – WS - Reporting
Each of the interface between those layers is done by a set of classes named model interfaces.
-          Data model: is the separation between DAO and Service
-          Data Transfer Object model implements the model for exchanging with exposure layer. You can have HMIDTO, WSDTO and Reporting DTO. Actually, you can have as many
Apart from those two major class, you may have the transverse layer
-          Utility classes, for sharing common routines in classes
-          Formatting, internationalization and conversion classes
-          System interface classes

Action layer

For the interface between action layers you shall use models
Data Layer
The data layer is typically in charge of communicating with the lower layer. DAO communicates with services using the object model.
Service Layer
The service layer contains the actions that make sense for the business. They are named upon there objective. For instance, the service named EmployeeService will group the methods applying to an employee.  
In large project, it is a good practice to have one service for each Exposure Layer. For instance, you would have:
-          EmployeeHMIService for performing task linked to HMI
-          EmployeeWSService for performing task linked to the Web Service Apis
However, this rule maybe unworthy on small projects.
Services communicates with the exposure service using DTO (data transfer objects)
This service separation is done thanks to packages

Model interfaces

Data Access Model
Data access model is something very close from the structure in the database.
It is a good principle not to reuse the data model interface for the exchange with the exposure layer in order to guarantee a good layer separation.
Data Transfer Model
The data transfer model is used to connect with the exposure layer. It only contains the data necessary to the upper level.
It has not to be uniquely bound to a same concept. For instance, if you have a table displaying a list of employees with only name and first name. You may have a bean with only two fields. While, if you want to produce a screen with the employee detail, you may create a DTO with all the employee fields.
It is a good practice to closely to transform the Data Access Model with some specific methods of the service.
For instance, you would have two methods in the employee service
-          EmployeeDetailHMIDTO  transformEmployee2EmployeeDetailHMI(Employee)
-          EmployeeListHMIDTO  transformEmployee2EmployeeListHMI(Employee)

Tranverse component