~ marked steps will be replaced with dependency injection in the following steps.
Start to move all business logic from view controller into view models.
~ Initialize view models in the view controllers.
Start to define data-related methods (from view models) into repository interfaces based on domains.
Implement the repositories with a mix of local/remote data sources and data modifiers.
~ Declare the repositories as singletons.
~ Call the methods from repository singleton instances in view models.
Separate the data sources into local and remote.
Local data sources will be used to cache data temporarily or persistent.
Remote data sources handle the network requests.
Start to combine the connected repository methods into use case classes.
~ Singleton instances of the repositories should be called in use cases,
View models should not be aware of the repositories, only use cases should be called.
~ Initialize the use case instances each time in view model methods.
Start to divide the existing project structure into 3 modules: presentation
, domain
, data
.
All UI components should be placed in the presentation
module.
- UI components can access only domain module components.
- Data management should be handled over the use case classes.
- Register view models as a factory.
- Inject use cases as constructor parameters in view models.
Use cases, repository interfaces, and entity models should be placed in the domain
module.
- Domain module elements should be accessible from
presentation
anddata
modules. - Entity models should not be serializable.
- Register use cases as a factory.
- Inject repositories as constructor parameters in use cases.
All repository implementations and data sources should be placed in the data
module.
- Data sources should not be accessible from outside the module.
- Data serialization, network connectivity, and local database access should be done in the data module.
- Register local data source implementations as a singleton.
- Register remote data source and repository implementations as a factory.
- Inject data sources as constructor parameters in repositories.
In the following links you can find module separation tutorials:
In the following links, you can find starter projects: