Unbloating objects with the SRP
When we talk about making good code bases, the SRP is the main principle for designing cohesive and focused classes. It helps us create classes that are cleaner but also easier to manage and extend. At its core, the SRP states that a class should have one, and only one reason, to change. This means that when adding or removing functionalities to this class, you should always ask yourself: Does this deviate from this class’ purpose? Does this help it perform its core function? In that sense, the SRP helps us encapsulate a single responsibility or functionality.
This principle challenges the common inclination to create bloated classes with “jack-of-all-trades” purposes that handle multiple aspects of a game. A bloated class is a class that has become overly large and complex, often containing too many responsibilities, methods, or properties. This can lead to difficult maintenance and testing, and potential bugs, as the class tries...