Inheritance or Composition

Inheritance or Composition

These slides are the material that I use as support on my talk about Inheritance and Composition on Android.

Af711eb0c3c1b567efeee6376462c6e1?s=128

Txus Ballesteros

July 18, 2016
Tweet

Transcript

  1. ≥ Welcome!

  2. ≥ Txus Ballesteros Android Engineer @txusballesteros +txusballesteros github.com/txusballesteros

  3. ≥ Green Programming™

  4. ≥ Programming focused on nature aspects.

  5. ≥ ≥

  6. ≥ Hi, I’m Ramón. ≥

  7. ≥ ≥

  8. ≥ ≥

  9. ≥ Sorry for the Fake!!!

  10. ≥ Inheritance or Composition?

  11. ≥ Composition or Composition

  12. ≥ ≥

  13. ≥ ≥

  14. ≥ Client Behaviour Behaviour Behaviour Behaviour Client Client Client Inheritance

    Strategy
  15. ≥ Client Behaviour Behaviour Behaviour Behaviour Client Composition Strategy

  16. ≥ Inheritance

  17. ≥ Inheritance common mistakes • Early adoption. • Architecture based

    100% on inheritance.
  18. ≥ Inheritance Bad Smells • Having infinite levels of inheritance.

    • Extents of a non abstract classes. • Base classes with more than 100 200 lines.
  19. ≥ Some responsibility mistakes…

  20. ≥ Activity.java Android Donut: 3.629 lines of code https://github.com/android/platform_frameworks_base/blob/donut-release/core/java/android/app/Activity.java Android

    KitKat: 5.468 lines of code https://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/app/Activity.java Android Marshmallow: 6.649 lines of code https://github.com/android/platform_frameworks_base/blob/marshmallow-release/core/java/android/app/Activity.java
  21. ≥ Fragment.java Android ICS MR1: 1.564 lines of code https://github.com/android/platform_frameworks_base/blob/ics-mr1-release/core/java/android/app/Fragment.java

    Android KitKat: 1.920 lines of code https://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/app/Fragment.java Android Marshmallow: 2.559 lines of code https://github.com/android/platform_frameworks_base/blob/marshmallow-release/core/java/android/app/Fragment.java
  22. ≥ TextView.java Android Donut: 7.317 lines of code https://github.com/android/platform_frameworks_base/blob/donut-release/core/java/android/widget/TextView.java Android

    KitKat: 9.231 lines of code https://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/widget/TextView.java Android Marshmallow: 10.194 lines of code https://github.com/android/platform_frameworks_base/blob/marshmallow-release/core/java/android/widget/TextView.java
  23. ≥ How I can take the decision?

  24. ≥ S O L I D RP Single Responsibility CP

    Open Close SP Liskov Substitution SP Interfaces Segregation IP Dependency Inversion
  25. ≥ S O L RP Single Responsibility CP Open Close

    SP Liskov Substitution
  26. ≥ Composition

  27. ≥ Where can you use composition?

  28. ≥ Everywhere… “You're using composition and you don't know it”

  29. ≥ Let’s Start…

  30. ≥ Views & ViewGroups

  31. ≥ List & RecyclerViews

  32. ≥ List Adapter List using adapters…

  33. ≥ List Renderer List composing with renderers… Renderer Renderer Renderer

  34. ≥ Fragments

  35. ≥ Activity Fragment Fragments most common usage…

  36. ≥ Activity Fragment Fragment Fragments activities composition…

  37. ≥ Activity Fragment Fragment Fragment Fragment Fragments activities composition…

  38. ≥ Activity Fragment Fragments activities composition…

  39. ≥ Activity Fragment Fragments activities composition… Activity Activity

  40. ≥ Activities

  41. ≥ Toolbar Activity composing Activities… +

  42. ≥ Activity composing Activities… Activity AbsActivity Activity

  43. ≥ Activity composing Activities… Loading Activity Activity Toolbar FAB

  44. ≥ Tools

  45. ≥ Java 8 & Defaults

  46. ≥ Mara https://github.com/txusballesteros/mara

  47. ≥ We’re Hiring jobs@wallapop.com

  48. ≥ Thanks for Coming