AspectJ Android with Example

16
Introduction to AspectJ Erol KOCAMAN GDG Istanbul 25/10/2014

description

AspectJ Android with Example

Transcript of AspectJ Android with Example

Page 1: AspectJ Android with Example

Introduction to AspectJ

Erol KOCAMAN

GDG Istanbul

25/10/2014

Page 2: AspectJ Android with Example

Peak Games

Page 3: AspectJ Android with Example

Peak Games

Page 4: AspectJ Android with Example

Agenda

● Why we use AOP ?● Cross Cutting Concerns● Aspect Implementations in Java● AOP with OOP● AspectJ Compiler● Demo Project

Page 5: AspectJ Android with Example

Why do we use AOP ?

GAME 1

Module 1

Module 2

Module 3

GAME 2

Module 4

Android

IOS

Desktop

Page 6: AspectJ Android with Example

Cross Cutting Concerns

In App Billing Networking Game

Logging Analytics Profiling

Page 7: AspectJ Android with Example

After Aspect

In App Billing Networking Game

Logging

Aspect

Analytics

Aspect

Profiling

Aspect

Page 8: AspectJ Android with Example

AOP / OOP

● OOP is encapsulation of module for better understanding

● You can even do the same thing with OOP by coding more

● AOP is valid for all programming paradigms

Page 9: AspectJ Android with Example

Aspect Implementations

● AspectJ● Spring AOP● JBossAOP● JAC● Colt● PROSE

Page 10: AspectJ Android with Example

Java & Aspect

Source Files

AspectJ Compiler

Java & Aspect

Archive Files

(.jar)

Java & Aspect

Archive Files

(.jar)

Java & Aspect

Archive Files

(.jar)

AspectJ

Compiler

(ajc)

Woven system

(.class files)

Java & Aspect

Source FilesJava & Aspect

Source Files

(.java)

Page 11: AspectJ Android with Example

Program Execution

Terminology

Join Points

Pointcut

// aspect codeif (...) {

...} else {

...}

Advice

Page 12: AspectJ Android with Example

JoinPoint Types

● Method● call● execution

execution(* android.mobile.peakgames.net.aspectjandroid.AspectActivity.fetchImage(..))

● Constructorexecution(* android.mobile.peakgames.net.aspectjandroid.AspectActivity.new(..))

● Field Access ● Exception Handler Execution● Class Initialization

Page 13: AspectJ Android with Example

Call / Execution Aspect Difference

ATM Account

debit(...)

Call Execution

Aspect

Aspect

Page 14: AspectJ Android with Example

AspectJ Annotations

@Aspect@Pointcut@Before@After@AfterReturning@AfterThrowing@Around

Page 15: AspectJ Android with Example

https://github.com/firstthumb/AspectJ-Android-Example

Code with sample

Page 16: AspectJ Android with Example

We are Hiring!www.peakgames.net

Thank You!