GENERIC-6: Organize your Java/Kotlin packages and files either by layer or by app feature.


Description

By organizing your packages and files it becomes easier for programmers to find the code which performs a certain aspect of your application. Whenever a feature has to be changed in layer-organized file system, multiple files in different packages need to be changed. As however in packaging by feature this is less the case.

Example

Our MVVM-example somehow needs to reflect that it uses this architecture.

Rxjava packages

As you can see there are three main packages:

  • Service
  • View
  • ViewModel

In the service package everything with data preparation is taken care of. E.g. fetching data from the server. Putting the fetched data into mutableLiveData. The ViewModel exposes methods which help maintain the View. And the View handles the UI events and maps them to them to the ViewModel.

Our MVP also somehow needs to reflect it’s architecture.

MVP packages

As you can see there are three main packages:

  • View
  • Model
  • Presenter

In the model all the data management is taken care of. The Presenter queries the data from the model, and returns it to the View. And the View presents the data to the user in a way the Presenter decided.

Check out both the MVVM example and the MVP example on these links.