Architectural Guidelines - scg-unibe-ch/ese2016 GitHub Wiki

1. Naming

  • The names of classes modeling services should end with the suffix Service. The suffix Service should only be used for service classes.
  • The names of classes modeling a controller should end with suffix Controller. The suffix Controller should only be used for controller classes.
  • The names of classes modeling a form should end with the suffix Form. The suffix Form should only be used for form classes.
  • The names of classes modeling DAO objects (repositories) should end with the suffix Dao. The suffix Dao should only be used for DAO objects.

2. Package structure

  • All controller objects should be placed in a single package named <your_package_prefix>.controller. You can choose the name for <your_package_prefix>. The package <your_package_prefix>.controller should only contain controller classes. Utility classes needed by controllers should be placed in a package named <your_package_prefix>.controller.utils.
  • All service objects should be placed in a single package named <your_package_prefix>.controller.service. The package <your_package_prefix>.controller.service should only contain service classes. Utility classes needed by services should be placed in a package named <your_package_prefix>.controller.service.utils
  • All classes modeling forms should be placed in a single package named <your_package_prefix>.controller.pojos.forms. The package <your_package_prefix>.controller.pojos.forms should only contain forms.
  • All model entities should be placed in a package named <your_package_prefix>.model. The package <your_package_prefix>.model should only contain model entities or enumerations needed by model entities. Other utility classes needed by model entities should be placed in a package named <your_package_prefix>.model.utils.
  • All classes modeling DAO objects should be placed in a package named <your_package_prefix>.model.dao. The package <your_package_prefix>.model.dao should only contain DAO classes.

3. Dependencies

  • Controller objects should not be referenced or called directly from any part of the system. This includes also jsp files. Currently the file getsipcodes.jsp is an exception to this rule. You do not have to fix this, however, you should not access services this way.
  • Forms should only be accessed by controller and service classes.
  • Service classes should only be accessed by controller classes or other service classes.
  • DAO classes should only be accessed from service classes.
  • Model classes should only reference classes from the package <your_package_prefix>.model or any of its sub-packages.
  • All dependencies to external jars or libraries should be specified through maven. The maven command ‘mvn validate’ should not fail.

4. Design

  • Within a service class attributes that point to Dao objects (repositories) or other services must be annotated with @Autowired and not initialized explicitly.
  • Within a controller attributes that point to services should be annotated with @Autowired and not initialized explicitly.
  • Within a controller all public methods should be annotated with @RequestMapping or @ModelAtrribute.
  • DAO objects and services should only be stored in instance attributes
  • All access to the database should be done through DAO objects. You should not use SQL queries to extract data from the database. Currently the service GeoDataService breaks this rules. You do not have to fix this service, however, you should not use SQL queries in any other services.
  • Form classes should only contain accessors and attributes.
  • All requests to controller objects should have logging support. A log entry should be added when a controller receives a request and when the controller completes a request. For example if a request is done to /profile/placeAd there should be a log entry that the controller PlaceAdController received this request and that the controller handled the request (successfully or with an error). Log entries should be placed in the file controller.log. Log entries should contain relevant information related to the request. Log entries should follow a common structure.

5. Testing

  • Any path exposed by a controller should have a test.
  • Data should be added into the database using dedicated service classes
  • Tests for services, controllers and DAO objects should be in test classes should be run using the SpringJUnit4ClassRunner.
  • All services populating the database with test data, should be placed in the package <your_package_prefix>.test.testData. This package should only contain services providing test data.
  • The name of service classes placed in the package <your_package_prefix>.test.testData should end with the suffix Saver