I have done some Android applications using MVP methodology,
But I am not so sure if it is better to place different layers objects of the same feature in a same package? or package all layers items of different features in the same package with layer name on it?
(Which I mean something like this)
Currently, I am following the second rule, but is this the best practice?
Edit: This is my project's whole packages! :)
Just to throw my thoughts into the mix. I have worked on projects with each of these approaches. My preference now is to package by feature. There are two main reasons I prefer this approach:
Ease of Induction
Increased visibility of project structure for developers new to the codebase. When classes which relate to a single feature are grouped together it is much easier for a new team member to quickly see how everything fits together.
Restricting Class access
This is probably more important. When you package by type (all Presenters together, etc) you have to give many methods in these classes public
access. This can lead to these functions being used inappropriately from various areas of the codebase.
If you package by feature then these classes are all in the same package and as such you can give the methods package level access. This ensures that methods don't leak.
Create a feature-specific package which contains a Contract
interface
containing the View
and Presenter
interfaces. The feature package also contains implementations of the View
and Presenter
interfaces (i.e. the Activity
and Presenter
classes).
I have made a sample project here; you may refer it for more info on MVP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With