Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Tech-improvement: Refactor high-complexity classes #888

Open
psh opened this issue Sep 23, 2017 · 7 comments
Open

Tech-improvement: Refactor high-complexity classes #888

psh opened this issue Sep 23, 2017 · 7 comments

Comments

@psh
Copy link
Collaborator

psh commented Sep 23, 2017

Address the very high cyclomatic complexity we are seeing from Codacy by breaking up Activities & Fragments according to one of the well-respected architectural patterns (MVP / MVVM / etc)

@maskaravivek
Copy link
Member

As part of #1092, we are looking to introduce a consistent pattern for our backend codebase. The same consistency should be followed for our presentation layer. There are several architectures out there and some of the most popular ones are MVP and MVVM. We already use MVP for our uploads flow and also for displaying campaigns(thanks to @ashishkumar468).

Am adding linkings to a few insightful blog posts which talk about how and why to use MVP in android.

IMO, our app would benefit from following a standard architectural pattern for its presentation layer mainly because it would provide a clear understanding of structuring code and avoiding code smells to all contributors.

Some of the anti-patterns that I observe and hope to fix as a team is:

  • not concerning yourself the lifecycle of Fragment and Activity. This leads to crashes, most commonly because of null context.
  • referencing view elements of a particular Fragment or Activity directly in a different fragment or activity. This makes it harder to decouple different fragments.
  • defining public methods in a fragment that is referenced from another activity or fragment. Ideally, we should use interfaces and listeners instead of calling public methods directly.
  • a Fragment or Activity have high cyclomatic complexity. Ideally, these classes should have clean public interfaces and any communication between these elements should be through proper channels.
  • A lot of business logic is present in the view layers. These should be extracted out to the presentation layer. Having things in the view layer itself leads to code duplication as well.

@misaochan
Copy link
Member

There seems to be a bit of a duplicate here. I was intending for #1092 to be the main issue for this task, with #1863 for reference. Shall I close this issue and move your comment over to #1092 , @maskaravivek ?

@maskaravivek
Copy link
Member

maskaravivek commented Feb 14, 2019

Yes I agree #1092 should be the main issue but it might get messy to have all the discussion on that thread. I thought it would be easier to follow the discussion if we have separate issues for mediawiki apis(retrofit and okhttp), shared prefs, presentation layer, content providers etc, keeping #1092 as the parent issue.

Edit: If you intend to keep the discussion at one place, feel free to close this issue and we can continue the discussion on #1092. We can probably crease separate issues while actually implementing the changes. :)

@misaochan
Copy link
Member

Sorry for the delay in response, @maskaravivek . I just went through the articles on MVP and it looks good to me - I especially like that it benefits testability and reusability. :)

I would be on board with using this architecture for our backend overhaul. If anyone disagrees or would like to propose a different one, now is the time to speak! ;) The official announcements for approved grants will be out in a week's time, and Vivek has requested to start on this task ahead of time if possible.

@ashishkumar468
Copy link
Collaborator

I agree with @misaochan on the benefits. Even my vote goes for MVP.

@misaochan
Copy link
Member

misaochan commented Mar 12, 2019

As there are no contradicting opinions, we will be going with MVP. :)

In order to maintain consistency in our codebase, we are thinking of requiring that all new PRs created after a certain date should adhere to this architecture, as well. This would apply to all volunteers, interns, and grantees - since there is no purpose in doing this overhaul if we are not going to maintain its consistency. Of course, by its very nature, this is unlikely to affect bugfixes and very small enhancements (for instance, if you just fix a NPE, we are not going to expect that you will refactor all the code surrounding it) - it is only larger changes and large enhancements that would be affected.

If no one has issues with this, I will create the rule for all PRs created after 18th March, and update our wiki. This may also tie in with new contribution guidelines if we reach a consensus at #2553

@misaochan
Copy link
Member

Added a rule to our wiki for this: https://github.com/commons-app/apps-android-commons/wiki/Code-style

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants