The open/closed principle states that classes, modules and functions should be open for extension, but not to modification.
You might wonder what the idea behind this is. Following this principle suggests that you should be able to add functionality without having to alter existing code. In order to use this principle, you need to have an OOP language that provides access to inheritance.
Inheritance allows to create several implementations of an interface that offer a set of functionalities. The interface simply determines the accessible methods, these are implemented in the classes that inherit from the interface.
Unfortunately interfaces can only be implemented in GameMaker Studio to a certain degree. This might make following SOLID design principles more difficult. However, the idea behind this can still be followed.
So what can be done to minimize the amount of code that needs to be changed when adding functionality?
- Adhere to the Single Responsibility Principle. It helps to split your code into manageable segments.
- Don’t be afraid to utilize parent/child relations in GameMaker. If you do not override the functionalities you only need to edit in the parent class (object in GM). You can minimize the amount of times that you need to override by defining your variables in your create event. Magic numbers (values not bound to variables) are generally a bad idea.
- You can use scripts and functions to separate functionalities. This way you can also organize your events and keep everything neat and readable. With the additional benefit of only having to create/adjust the specific script/function when modifying or creating functionality.
I hope you found this little description/guide helpful! 🙂