Single Responsibility Principle

Single Responsibility Principle:

The single responsibility principle states that each class (object in GameMaker) should have one, and only one reason to change. In order to understand why this matters lets imagine you are working on a project that has a significant size. Over time, you might want to make changes to your code base, and you decide to update a functionality. But now a lot of functionalities are broken, because the class responsible for the edited functionality also dealt with other stuff, and apparently there were dependencies that broke the code.

As you change your code it may also become much more difficult to manage the code base since a class/object isn’t simply responsible for one functionality/aspect.

Splitting up your functionalities over multiple classes/objects has the following benefits:

-Arguably easier to navigate between functionalities.

-You don’t risk breaking a bunch of other functionalities when you edit or remove an object.

-Improve development speed by better organizing your code.

How do you determine the responsibility of an object/class? Ask yourself, “What is this object responsible for?, “What does it do?” and when should it change?”

To provide an example, if you have an object obj_player, it should only be responsible for things the player can do or essential to it functioning properly. Such as movement, damage, and key input. What it should not be responsible for is the camera, managing the health of enemies, drawing a gui, etc.

Should you always follow this principle?

That is up to your own preference. I would suggest to take a look at the pros and cons of using it. If you have a very small project, it may not be beneficial because it would only slow you down. In the case of a very large project, it may well be worth considering!