Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AOP and AspectJ

AOP and AspectJ

Technokratos Android Meetups #1. By Kazakov Anton.

Avatar for Technokratos

Technokratos

July 07, 2018
Tweet

More Decks by Technokratos

Other Decks in Programming

Transcript

  1. Code tangling problem Business Logic Analytics Security One module -

    many concepts implemented (single responsibility break)
  2. Accounts Module Code scattering problem Authorization Module Maps module Analytics

    Module Single functionality in many modules (code duplication)
  3. Main concepts of AOP systems • Identifiable execution points in

    system • Construct to select these points • Construct to dynamically change app behaviour • Construct to alter static structure of the system • Module to gather all contracts in one place
  4. • thisJoinPoint: target object execution object arguments annotations • thisJoinPointStaticPart

    source location signature of join point type of join point • thisEnclosingJoinPointStaticPart enclosing joint point Reflective access
  5. Aspects precedence • Higher priority before() advices weaves BEFORE Aspects

    with lower priority • Higher priority after*() advices weaves AFTER Aspects with lower priority • Higher priority around advices incapsulate advice with lower priority
  6. SOURCE CODE WEAVING BYTE CODE WEAVING BUILD TIME WEAVING ✅

    ✅ LOAD TIME WEAVING ❌ ONLY IN XML FILES, WITH LIMITATIONS ✅ AspectJ Weaving Models comparison
  7. Woven code .jar/.class Java source files AspectJ source files AspectJ

    .aj files ajc Build-time source code weaving
  8. Java source files AspectJ source files AspectJ .aj files Java

    bytecode AspectJ bytecode AspectJ with native syntax bytecode javac/ajc javac/ajc ajc Build-time source code weaving Woven code .jar/.class ajc
  9. AspectJ @AspectJ Simple and plain; Lot of annotations with String

    body Support Exception softening Method and data introduction Privileged access Low ITD abilities Doesn’t need AJC to compile code. Additional step to build process Need ajc Poor support in Android Studio Good IDE/Plugins support/Spring intro AspectJ vs @AspectJ
  10. ajc + aspetjrt.jar HujiangTechnology/ aspectjx 1000⭐ Archinamon/android- gradle-aspectj 160⭐ command-line

    access to ajc small size good for pure java projects not good for android works with multidex and lambda native toolchain can weave kotlin/scala/ groovy support Instant run Gradle 2/3/4 support do not support AspectJ native syntax docs/issues in Chinese written in Groovy works with multidex 100% Kotlin supports both syntaxes highly customisable supports instrumented tests issues with native lambda(milestone to 3.3.0) Plugins
  11. Cons •Not obvious app behaviour/lack of visibility •Problems with tooling

    especially in Android •Increased binary file size •Would be better if aspects was language feature •Increased build time/class load time Pros … Pros and cons