Understanding dependencies

We will start with writing a simple example; a business service talking to another data service. Most Java classes depend on other classes. These are called dependencies of that class.

Take a look at an example class BusinessServiceImpl, as follows:

    public class BusinessServiceImpl {       public long calculateSum(User user) {         DataServiceImpl dataService = new DataServiceImpl();         long sum = 0;         for (Data data : dataService.retrieveData(user)) {           sum += data.getValue();         }         return sum;       }    }

Typically, all well-designed applications have multiple layers. Every layer has a well-defined responsibility. The business layer contains the business logic. The data layer talks to the external interfaces and/or databases to get ...

Get Mastering Spring 5.0 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.