These slides are the material that I use as support on my talk about Inheritance and Composition on Android.
≥Welcome!
View Slide
≥Txus BallesterosAndroid Engineer@txusballesteros+txusballesterosgithub.com/txusballesteros
≥Green Programming™
≥Programming focused onnature aspects.
≥≥
≥Hi, I’m Ramón.≥
≥Sorry for the Fake!!!
≥Inheritance or Composition?
≥Composition or Composition
≥ClientBehaviourBehaviourBehaviourBehaviourClient ClientClientInheritance Strategy
≥ClientBehaviour BehaviourBehaviour BehaviourClientComposition Strategy
≥Inheritance
≥Inheritance common mistakes• Early adoption.• Architecture based 100% on inheritance.
≥Inheritance Bad Smells• Having infinite levels of inheritance.• Extents of a non abstract classes.• Base classes with more than 100 200 lines.
≥Some responsibility mistakes…
≥Activity.javaAndroid Donut: 3.629 lines of codehttps://github.com/android/platform_frameworks_base/blob/donut-release/core/java/android/app/Activity.javaAndroid KitKat: 5.468 lines of codehttps://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/app/Activity.javaAndroid Marshmallow: 6.649 lines of codehttps://github.com/android/platform_frameworks_base/blob/marshmallow-release/core/java/android/app/Activity.java
≥Fragment.javaAndroid ICS MR1: 1.564 lines of codehttps://github.com/android/platform_frameworks_base/blob/ics-mr1-release/core/java/android/app/Fragment.javaAndroid KitKat: 1.920 lines of codehttps://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/app/Fragment.javaAndroid Marshmallow: 2.559 lines of codehttps://github.com/android/platform_frameworks_base/blob/marshmallow-release/core/java/android/app/Fragment.java
≥TextView.javaAndroid Donut: 7.317 lines of codehttps://github.com/android/platform_frameworks_base/blob/donut-release/core/java/android/widget/TextView.javaAndroid KitKat: 9.231 lines of codehttps://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/widget/TextView.javaAndroid Marshmallow: 10.194 lines of codehttps://github.com/android/platform_frameworks_base/blob/marshmallow-release/core/java/android/widget/TextView.java
≥How I can take the decision?
≥S O L I DRP Single ResponsibilityCP Open CloseSP Liskov SubstitutionSP Interfaces SegregationIP Dependency Inversion
≥S O LRP Single ResponsibilityCP Open CloseSP Liskov Substitution
≥Composition
≥Where can you use composition?
≥Everywhere…“You're using composition and you don't know it”
≥Let’s Start…
≥Views & ViewGroups
≥List & RecyclerViews
≥ListAdapterListusing adapters…
≥ListRendererListcomposing with renderers…RendererRendererRenderer
≥Fragments
≥ActivityFragmentFragmentsmost common usage…
≥ActivityFragmentFragmentFragmentsactivities composition…
≥ActivityFragmentFragmentFragmentFragmentFragmentsactivities composition…
≥ActivityFragmentFragmentsactivities composition…
≥ActivityFragmentFragmentsactivities composition…ActivityActivity
≥Activities
≥ToolbarActivitycomposing Activities…+
≥Activitycomposing Activities…ActivityAbsActivityActivity
≥Activitycomposing Activities…LoadingActivityActivityToolbarFAB
≥Tools
≥Java 8 & Defaults
≥Marahttps://github.com/txusballesteros/mara
≥We’re Hiring[email protected]
≥Thanks for Coming