[Solved] Violating Single Responsibility Principle and static methods [closed]


A few random thoughts.

(a) Can you even pin down precisely what it means for a class to have some “responsibility” ??? And subsequently, if (as I suspect) all you have is vague notions without any formally observable / measurable properties / characteristics to pin down the meaning of “responsibility”, then how can you say as unequivocally as you do that what you have is violating it ?
(b) If your application grows large enough or you want certain advanced means (JMX) to interact with your running application, you will split “MyEngine” and “StartMyEngine” just naturally as you go. Methinks. If your application is not large/advanced/complex/critical/… enough, then not having that split will not matter much.
(c) Every instance method M(args) is the semantic equivalent of a static method SM that has all of args plus an argument of the type of the instance. So an instance method M() on class Foo is equivalent to a static method SM(Foo foo). This starts to reveal why your static print method “does not belong” in class BlackJackGame : it does not have any argument of type BlackJackGame and therefore cannot ever be said to relate in any way to the BlackJackGame type. Fundamentally speaking the same holds of course for main(String[]) but in that case its usage has become a common pattern, and moreover, there has to be an entry point somewhere somehow otherwise no java process could ever get started at all.

7

solved Violating Single Responsibility Principle and static methods [closed]