This is a very strange example, because SetGrid does not seem to perform many other tasks than setting some default values. You also allow the code to manipulate the object, which can very well do it on its own. The value of IGrid and ProjectModel can be reorganized into this:
public interface IGrid {
Using this refactoring, you need to do the same with this:
myProjectModel.setDefaults();
You can also create an abstract base class that implements IGrid , which implements the setDefaults() method, and ProjectModel extends the abstract class.
What about SOLID principles? Specifically, the principle of shared responsibility. The class is primarily similar to the DTO. - user137348
I am implementing the principle of segment separation from SOLID principles here to hide the implementation from the class client. That is, therefore, the client does not need to access the internal functions of the class used, otherwise this is a violation of the principle of least knowledge .
The Single Responsibility Principle (SRP) only says that a class should have only one reason for change, which is a very vague restriction from the moment of change that can be as narrow and wide as you want.
I believe that itβs quite normal to insert some configuration logic into the parameter class if it is small enough. Otherwise, I would put all this in a factory class. The reason I propose this solution is because IGrid seems to reference PagerHelper and SortHelper , which seem to be IGrid for IGrid .
Therefore, it seemed strange to me that you note that the class is a DTO . From a purist sense, a DTO should not have logic except accessories (i.e. getter methods), which makes it strange that ProjectModel itself has links to PagerHelper and SortHelper , which, I believe, can mutate (i.e. retailers). If you really want SRP, the helpers should be in the factory class that creates the IGrid / ProjectModel instance.