Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3756

"@Service" classes should not have communication-related members

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Move this "xxTypexx" member and its use to a DAO class.
    • Highlighting:
      Hide

      member declaration

      Show
      member declaration
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Targeted languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      20min
    • Analysis Scope:
      Main Sources

      Description

      A cleanly coded web application will have a clear separation of concerns, with business logic in the @Service layer, and communication with other systems in the data access layer.

      To help enforce such a separation of concerns, this rule raises an issue when a @Service class has RestTemplate, JmsTemplate, WebServiceTemplate, JdbcTemplate, or DataSource member.

      Noncompliant Code Example

      @Service ("greetingmanager")
      public class GreetingManagerImpl implements GreetingManager
      {
          @Autowired
          DataSource ds;  // Noncompliant
      

      Compliant Solution

      @Service ("greetingmanager")
      public class GreetingManagerImpl implements GreetingManager
      {
          @Autowired
          GreetingDao gdao;  // DataSource and its use have been moved here
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: