mardi 16 mai 2017

Framework for UI management - Design improvement

I am in the middle of writing a small structure to serve as a framework for handling the 2D GUI of a Unity3d project. I have one empty gameobject called "UIManager" with "UIManager" script on it. UIManager is a Singleton with DontDestroyOnLoad. Now here is a problem, it works for all practical purposes but design wise, i am openly revealing my implementation (that it is a singleton) to the rest of the world/project. I need suggestion on how it could be improved such that it is better encapsulated.

For a better design of the problem, I stumbled upon Service Locator Pattern. Now I am even more confused. If i am understanding it correctly, I still declare my UIManager as singleton, but instead of getting it's reference via something like UIManager.GetInstance()... I create another Singleton of "ServiceLocator" and ask it for an instance of UIManager. I don't see how it improves the encapsulation of my UIManager class, whose implementation still remains public. And I don't see how it helps with decoupling.

Any insight into the issue? How do you prefer to do it?

Aucun commentaire:

Enregistrer un commentaire