I'm facing some issues related to code duplication when following MVP architectural pattern in an Android project that I'm working with. My project structure is separated by packages: data, domain, infra, ui. Inside ui package there are another packages for each screen of the app. Most of them contains this structure:
- Contract: contains two interfaces, one for the view and another for the presenter;
- Activity: which inherits view interface and implements some methods;
- Presenter: contains very little business rules and communicates with my model;
I have another two interfaces (BaseView and BasePresenter) for the minimum of a View and a Presenter needs to implement.
Some of my screens has so much common code. They differ basically in layout and some specifics. This behavior occurs due to adoption of MVP rules (each view has its presenter).
I have found two answers for this issue on SO:
One suggests the creation of a base presenter class with common methods or an abstract class and the other accepts how the things are. I'm going to implement the base presenter or the abstract class, which leads to my question:
Based on the mentioned structure how can I achieve a good result without affecting or hurts a little this structure? Do I create a new package for this abstract class or base presenter? I believe this approach dirts the whole structure. So, what do I need to do?