Implementing the Service Locator pattern in Godot Engine
The Service Locator pattern is a simple pattern conceptually, as we saw in this chapter. It essentially provides a wrapper class for common services in our game’s code base, allowing user classes to decouple from repetitive procedures, delegating them to the Service Locator. To make it clear again, this pattern can be implemented in many ways: as a static class, as a dependency injected on the user class upon initialization, and as a globally accessible instance. In this section, we will take our fictional game designer’s request and see the proper approach to solve their demand, and, based on that, we will use Godot Engine’s built-in features to implement this useful pattern in our project. That said, let’s take a look at the game designer’s request.
“Hey hey!
It’s your friend, the game designer!
You know, that power-up thing was amazing! It took me some time to understand...