Your SlideShare is downloading. ×
0
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
5 Steps To Clean Your Android Code
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

5 Steps To Clean Your Android Code

1,159

Published on

Most Android apps follow the same pattern: a RESTful third-party service provides information represented as JSON and XML, and your task is to present that information and to communicate user actions …

Most Android apps follow the same pattern: a RESTful third-party service provides information represented as JSON and XML, and your task is to present that information and to communicate user actions to the service. Designing and understanding the way data flows into your architecture usually result in a much cleaner codebase. Here you'll be presented 5 useful insights that will help you write code that is a pleasure to read, easy to test and fun to change.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,159
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 5 Steps To Clean Your Android Code +Frankie Sardo
  • 2. Enchant me. Simplify my life. Make me amazing.
  • 3. Android UI Design Principles
  • 4. Android Software Design Principles ?
  • 5. Clean Code is UX for Software
  • 6. #1 Model Objects
  • 7. Automatic mapping is tempting
  • 8. Keep you objects in shape class Event { private final String name; private final Location where; private final DateRange duration; private final Type type; public Event(String name, Location where, DateRange when, Type type) { this.name = name; this.where = where; this.duration = when; this.type = type; if (name.isEmpty()) { throw new IllegalArgumentException("Event name is empty"); } if (type == WORKSHOP && when.includes(27TH_MARCH )) { throw new IllegalArgumentException("Workshops are scheduled after 27th of March"); } } public boolean clashesWith(Event otherEvent) { return duration.overlaps(otherEvent.duration) && where.equals(otherEvent.where); } }
  • 9. #2 External Services
  • 10. Responses are unpredictable
  • 11. Abstract over external APIs
  • 12. #3 Business Logic
  • 13. Concurrency is hard
  • 14. Define your user stories class SearchRepositoriesScenario implements Scenario { final SearchRepositoriesPresentation presentation; final GithubApi githubApi; final SearchRepositoriesRequest request; final Database database; public SearchRepositoriesScenario(...) { ... } public void run() { presentation.showLoading(); String keyword = request.getKeyword(); Repositories repositories = githubApi.searchRepositories(keyword); SearchRepositoriesResponse response = from(repositories); database.persist(response); presentation.updateList(response); presentation.hideLoading(); } }
  • 15. Keep modules loosely coupled
  • 16. #4 Boilerplate code
  • 17. Android code is verbose
  • 18. Say what you mean class SearchRepositoriesActivity extends ListActivity { @Inject SearchRepositoriesController controller; @Icicle String query; // github.com/frankiesardo/icepick protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleIntent(getIntent()); controller.displaySearch(query); } protected void onNewIntent(Intent intent) { super.onNewIntent(intent); handleIntent(intent); } private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { query = intent.getStringExtra(SearchManager.QUERY); controller.startSearch(query); } } public boolean onCreateOptionsMenu(Menu menu) { return MenuHelper.inflate(getMenuInflater()).search() .up(ParentActivity.class).help().into(menu); } }
  • 19. #5 Unit test
  • 20. Tests constrain your design
  • 21. Practice makes perfect
  • 22. Q&A Time #gaagbt github/frankiesardo novoda/blog

×