The single responsibility principle

Let's understand how circular dependency can be eliminated by applying the single responsibility principle. Let's assume you are following three modules in a system:

  • Salary module
  • Employee module
  • HR module

The Salary module generates salary and sends it over email. Generating salary depends upon the Employee module. To get a few details, such as the appraisal process, and reward points the Employee module depends upon the HR module. At this moment, the dependency hierarchy will be as shown in the following diagram:

At some point in time, let's say you need email functionality in the HR module. Since email ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.