In my app I have a single Activity architecture and for every Fragment I have defined a "View" class.
This "View" class contains the View state and the View actions, which refer to the view's data and actions.
For example, I have the "MainFragment.kt" and a relevant "MainView.kt" file that will be something like this:
object MainView {
data class MainState(...) {...}
sealed class Actions {
sealed class Navigate : Actions() {
object Back : Navigate()
data class NextScreen(...) : Navigate()
}
object DoSomething : Actions()
}
}
The "MainState" and the "Actions" are then imported and used in the "MainFragment.kt" and in its "ViewModel" class.
As you can see, "MainView" is defined as an object because I don't need to instantiate it. The way I use it I just use the data (state and actions) it contains. This is also a safer approach by design because I need to have only one instance of the "View" class existing at any time.
Possible Problem: However, since there are many Fragments and as a result many View classes that correspond to them, then obviously the app will have many objects. Of course these objects are statically allocated in memory and this may lead to increased memory use.
Question: Is there any better approach in how I can define my "View" classes? For example, if I define "MainView.kt" as a class (e.g. class MainView(){...}) instead of an object, will that be better in terms of memory allocation and performance?