A microservice should always have a small set of responsibilities. This definition is based on a principle called the single responsibility principle, which states that a class must have only one reason to change. In other words, a class with more than one motive to change would have more responsibilities, and would not be cohesive. This would create problems, such as high coupling between the responsibilities of a class, difficulty in reusing code, and difficult maintenance.
A class that had methods that are responsible for calculation, as well as methods for formatting the result, would be an example of a class with little cohesion. Let's look at the following example:
class Insurance {
public double calculateCotation (...) {...}
public String generatePDF (...){...}
public String generateXLS (...){...}
}
The first method (calculateCotation) is directly related to the business domain and the others (generatePDF and generateXLS) are related to the presentation of the calculated values.
Single responsibility principle (SRP)
Open closed principle (OCP)
Liskov substitution principle (LSP)
Interface segregation principle (ISP)
Dependency inversion principle (DIP)