Good practices to keep code clean

Asked

Viewed 258 times

-2

I develop on Android a few months and one thing I noticed is that the more features a screen has, the more messy the code gets!

How so?

Imagine an Activity that has Loading bar, various actions that make asynchronous calls, etc. the source code gets full of classes and well messy, know a good practice to group these classes in separate files? Any good practice is welcome!

  • Object orientation is responsible for this, create objects for what you need and modularize according to need. If the code is getting too large it is likely that it could have a different encapsulation.

  • 2

    Do not worry so much about this no, the recommendation of the Kyllopardium is good, precisely to prevail the composition of objects and delegation of responsibility in order to avoid monolithic and "rolled up" code. An idea is to section its interface in Fragments and distribute responsibilities among them. Another suggestion is to look at Android projects that are Open Source, on Github for example. A good one I recommend is the iosched: https://github.com/google/iosched. (The Google I/O app).

  • 1

    Not exactly the answer to your question, but try reading Robert C. Martin’s Clean Code. http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 At.

1 answer

2

I use the following structure to manage the packages and classes:

  • *.Activity - Group of classes handling activitys.
  • *.Adapter - Group of classes using Adapters.
  • *.broadcastreceiver - Group of classes receiving broadcast signals.
  • *.db - Group of classes handling database
  • *.db.Tables - Base class group of your database tables.
  • *.Fragments - Group of classes that manipulate Fragments in your project.
  • *.service - Group of classes that generate services in your program.
  • *.Sync - Group of classes using asynctask or other type of synchronization system.
  • *.Utilities - Group of auxiliary classes.

You can also create class packages according to your needs. Make good use of the concept of code modularization. Also comment your code, the comments help you when it comes to orienting yourself.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.