This is also a little preferable. Theoretically, itβs great to go through the levels as you do. Alternatively, if you need more than just setting levels, but providing additional functions (for example, saving levels), I usually use a separate class responsible for handling such things (for example, a repository, some class βManagerβ, etc. .). This class is then passed to the view on the constructor, preferably st alone is forced to provide it. Of course, to separate things, I use interfaces, and not specific implementations of st, it can look like this:
public class MyView { public MyView(ILevelLoader levelLoader){ this.levelLoader = levelLoader; } ... }
Often this may not work, because a view is something created by the framework directly and not by the application. In such a situation, you are forced to do this through a suitable setter. This is a kind of MVC / MVP pattern.
Just for your interest, you can also take a look at IoC containers and dependency injection. Guice , provided by Google, is a good infrastructure that I have already used on Android.
source share