Project Coding Guideline

It coding guideline of project. Prepared by technical lead. It is prepared on basis of application architecture. It tells us how to develop code for the project.

  1. DTO

      1. DTOs are POJO.

      2. DTOs are presenting Database Model.

      3. One DTO is created for one Table.

      4. DTO will extend BaseDTO.

      5. DTO will override getKey() and getValue() method to be used in drop down list.

      6. Attribute ID will be used as Non-Business Primary Key.

      7. JPA annotation will be used to map Table columns with DTO attributes.

  2. DAO

      1. DAO will contains data access logic.

      2. DAO will have CRUD operation, find and search methods.

      3. Annotation @Repository will be used to define DAO.

      4. DAO must have findByPK(id) method.

      5. All methods finding a record by unique key, will follow naming convention findByUniqueKeyName(param).

      6. DAO will propagate DataAccessException in case of underling ORM exception.

      7. SessionFactory must be injected in DAO.

      8. Must get current session object from session factory to perform database operations.

      9. SessionFactory will be auto-wired in DAO.

      10. DAO will be separated into Interface and implementation class.

    1. Service

      1. Service will contains business login and perform business operations.

      2. Annotation @Service will be used to define Service class.

      3. Service will handle declarative transaction with help of @Transactional annotation.

      4. All get, find and search methods must define Transactional attribute readOnly=true.

      5. Service will propagate business exceptions like DuplicateRecordException.

      6. DAO will be auto-wired in Service.

      7. Service will be separated into Interface and Implementation classes.

    2. Controller

      1. Annotation @Controller will be used to define Controller.

      2. It will contain navigation logic. Controller contains display and submit logic.

      3. GET method will be used to perform display logic of a View.

      4. POST method will be used to perform submit logic of a View.

      5. One Controller will contain navigation logic (display and submit methods) for all related Usecases. For example User Controller contains display and submit logic for Add/Update User, Search User, My Profile and Change Password usecases.

      6. Display method will follow naming convention displayXXX() and submit method will follow naming convention submitXXX().

      7. URL will be bound with controller class. URL should have prefix /ctl followed by class name e.g. /ctl/User, /ctl/College.

      8. Usecase URLs are bound with there respective methods in controller.

      9. Controller methods will have return type string that will return tile-name of view.

      10. Controller methods will receive form bean with model attribute name "form" (@ModelAttribute("form")).

      11. Controller methods will receive model object as parameter.

      12. POST methods will apply input validations with help of @Valid annotation.

      13. Preloaded data will loaded from preload() method.

  1. Form beans

      1. It is POJO class designed as per View.

      2. Contains form input elements, transferred from View to Controller and Controller to View

      3. Uses basic and hibernate annotation to apply declarative input validations.

      4. One Form is created for One View.

      5. It will inherit BaseForm class.

      6. FormBean will override getDTO() and populate() methods. Method getDTO() will create respective dto and populate data from form bean. Method populate() will populate form bean attributes from dto.

  1. View

      1. View will contain display logic.

      2. View will use JSTL tags to render model attributes and perform control statements.

      3. Spring tag will be used to display i18n messages.

      4. Spring form tag will be used to bind model with form elements.

    1. Other

      1. Beans will be auto discovered and autowired.

      2. Maven will be used to create build file .WAR.

      3. Build will be deployed on JBoss 7 server.