SlideShare a Scribd company logo
Aspect-oriented programming
The next level of abstraction on Android
Tibor Šrámek
AUGUST 26, 2015
2CONFIDENTIAL
Topics
Cross-cutting concerns1
Separation of cross-cutting concerns2
Basics of aspect-oriented programming3
AspectJ4
Examples5
3CONFIDENTIAL
CROSS-CUTTING CONCERNS
4CONFIDENTIAL
Cross-cutting concerns
Module 1
Module 3
Module 2
Event
Tracking
Caching
Logging
Error
tracking
Event
tracking 2
Event
tracking 3
Module 4
Imagine a simple system
5CONFIDENTIAL
Cross-cutting concerns
Module 1 Module 2 Module 3 Module 4 Module 5
original functionality functionality 1 functionality 2 functionality 3
functionality 4 functionality 5 functionality 6 functionality 7
Tangled & redundant code
6CONFIDENTIAL
AOP
7CONFIDENTIAL
What is AOP?
Module 1 Module 2 Module 3 Module 4 Module 5
original functionality functionality 1 functionality 2 functionality 3
functionality 4 functionality 5 functionality 6 functionality 7
8CONFIDENTIAL
What is AOP?
Modules in one layer
CCCs in a separate layer extracted from the
original modules (AOP is the glue)
9CONFIDENTIAL
What is AOP?
•AOP is an extension of OOP
•It increases modularity by the separation of CCCs
•Decreases code redundancy
•Adds functionality using injection without
modifying the original code
•Besides CCC separation it gives us power…
10CONFIDENTIAL
ASPECTJ
11CONFIDENTIAL
What is AspectJ?
•It’s an AOP extension for Java
•Very powerful
•Easy to learn and use
•Java code is valid AspectJ code
•AspectJ = Java + some magic
12CONFIDENTIAL
AOP terminology
•Advice - injected code
•Join point - a point of execution
•Pointcut - point of injection (set of JPs)
•Aspect - advice + pointcut
•Weaving - process of injection
13CONFIDENTIAL
Weaving
Weaving can be static (compile-time)
or dynamic (runtime)
14CONFIDENTIAL
Android integration
// build.gradle
apply plugin: 'android-aspectj'
buildscript {
dependencies {
classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.12'
}
}
// an annotation style AspectJ example aspect
@Aspect
public class LoggerAspect {
@Before("call(* MyClass.myMethod())")
public void onMyMethodCalled() {
Logger.log("My method is called.");
}
}
15CONFIDENTIAL
Advice types
•Before
code will be injected before the
given join point
•After
code will be injected after the
given join point
•Around
code will be injected instead of
the given join point
• AfterReturning, AfterThrowing
@Before("myPointcut()")
public void myAdvice() {
// do something here, e.g. null-guarding
}
@After("call(int *.*View+.get*(..))")
public void myAdvice(JoinPoint joinPoint) {
// A JoinPoint object contains information
about the execution context(method signature,
arguments, containing class, etc.)
}
@Around("myPointcut1() && !myPointCut2()")
public void myAdvice(ProceedingJoinPoint point) {
// Pre processing work..
point.proceed();
// Post processing work..
// Around is perfect e.g. to skip a method
if a parameter is null or to replace
a buggy method in a library
}
16CONFIDENTIAL
Pointcuts
•Method: call() & execution()
•Constructor: call() & execution()
•Field access: get() & set()
"execution(* *.myMethod(..))"
"call(private MyType.new(..))"
"get(String MyClass.name)"
Signature:
<modifiers> <return_value> <type>.<method_name>(parameter_list)
Signature:
<modifiers> <class_type>.new(<parameter_list>)
Signature:
<field_type> <class_type>.<field_name>
17CONFIDENTIAL
Advanced pointcuts
•Class initialization
•Object initialization
•Advice execution
•Exception handling
•Annotations
•Etc. (virtually any point in the execution)
18CONFIDENTIAL
Aspects
Aspects can:
•contain regular fields & methods
(e.g. for counting)
•track private fields & methods
(don’t have to break encapsulation)
•inherit from other aspects
(e.g. for reusing advices)
19CONFIDENTIAL
Aspects
Aspects also can:
•be inner classes
•be instantiated
•declare advice execution order
•implement inter-type declarations
20CONFIDENTIAL
USE CASES
21CONFIDENTIAL
Common applications of AOP
•Logging
•Tracking (event, error, performance)
•Persistence
•Validation
•Synchronization
•Security
22CONFIDENTIAL
AspectJ
Is it good for anything else besides the
separation of CCCs?
•Skip or replace methods
•Prevent or handle errors
•Dependency injection
•Separation of architectural layers
23CONFIDENTIAL
Dependency injection with AOP
Consider Dagger, if you want to satisfy a dependency
you have to:
•make a module
•make a component
•modify the dependent class
24CONFIDENTIAL
Dependency injection with AOP
With AOP you only have to do this:
@Aspect
class DependencyInjector {
@After("execution(Dependent.new(..))")
public void inject(JoinPoint p) {
Dependent dependent = (Dependent) p.getThis();
dependent.dependency = new Dependency();
}
}
25CONFIDENTIAL
Architecture with AOP
Imagine a simple architecture
@Aspect
public class MyAspect {
private MyView view;
private MyPresenter presenter;
private MyProvider provider;
@After("execution(MyView.onCreate(..))")
private void init(JoinPoint jp) {
view = (MyView) jp.getThis();
presenter = new MyPresenter();
provider = new MyProvider();
}
@After("execution(MyView.myButtonClicked(..))")
private void myButtonClicked() {
presenter.createRequest();
}
@AfterReturning(pointcut = "execution(MyPresenter.createRequest(..))",
returning = "request")
private void requestCreated(Request request) {
provider.sendRequest(request);
}
@After("execution(MyProvider.onResponse(..))")
private void responseArrived(JoinPoint jp) {
String result = presenter.processResponse((Response) jp.getArgs()[0]);
view.showResult(result);
}
}
26CONFIDENTIAL
Architecture with AOP
A system like this is:
•Modular (e.g. multiple presenters for a view)
•Flexible (e.g. don’t have to use interfaces)
•Easy to test (don’t have to mock anything,
test only what you want)
27CONFIDENTIAL
Tips & tricks
You have to implement something
• that probably will be removed in the future?
Put it to an aspect! You will have to just delete the aspect.
• for only one build variant? Put it to an aspect in that variant!
In many cases you will have to implement only the differences.
Unleash your imagination…
(but don’t try to build the whole system with aspects)
28CONFIDENTIAL
OUTRO
29CONFIDENTIAL
AOP supported languages
• Java
• Objective-C
• .NET (C# / VB.NET)
• C / C++
• Python
• Perl
• PHP
• JavaScript
• Groovy
• Ruby
• ActionScript
• Ada
• AutoHotkey
• COBOL
• ColdFusion
• Lisp
• Delphi
• Haskell
• Logtalk
• Lua
• Matlab
• Prolog
• Racket
• Smalltalk
• Etc.
30CONFIDENTIAL
Active users of AOP
•Microsoft
•Oracle
•IBM
•SAP
•Siemens
•Red Hat
•Epam
There is a whole paradigm called Aspect-oriented software development…
31CONFIDENTIAL
Useful links
• http://www.eclipse.org/aspectj
• http://fernandocejas.com/2014/08/03/aspect-oriented-programming-in-android
• https://github.com/uPhyca/gradle-android-aspectj-plugin
• https://www.youtube.com/watch?v=cq7wpLI0hco
• Google is your friend 
32CONFIDENTIAL
Literature
• Robert E. Filman, Tzilla Elrad, Siobhan Clarke, Mehmet Aksit: Aspect-Oriented Software
Development. Addison-Wesley Professional, October 2004, 800 pp. ISBN: 0321219767.
• Renaud Pawlak, Jean-Philippe Retaillé, Lionel Seinturier: Foundations of AOP for J2EE Development.
Apress, September 2005, 352 pp. ISBN: 1590595076.
• Ramnivas Laddad: AspectJ in Action: Practical Aspect-Oriented Programming. Manning Publications,
July 2003, 512 pp. ISBN: 1930110936.
• Siobhan Clarke, Elisa Baniassad: Aspect-Oriented Analysis and Design: The Theme Approach.
Addison-Wesley Professional, March 2005, 400 pp. ISBN: 0321246748.
• Ivar Jacobson, Pan-Wei Ng: Aspect-Oriented Software Development with Use Cases. Addison-Wesley
Professional, December 2004, 464 pp. ISBN: 0321268881.
• Joseph D. Gradecki, Nicholas Lesiecki: Mastering AspectJ: Aspect-Oriented Programming in Java.
Wiley, April 2003, 456 pp. ISBN: 0471431044.
• Russell Miles: Aspectj Cookbook. O'Reilly Media, December 2004, 331 pp. ISBN: 0596006543.
33CONFIDENTIAL
@After(“execution(* Presenter.present()”)
void endPresentation() {
presenter.say(
” Thank You”
);}

More Related Content

What's hot

Functional Tests Automation with Robot Framework
Functional Tests Automation with Robot FrameworkFunctional Tests Automation with Robot Framework
Functional Tests Automation with Robot Framework
laurent bristiel
 
Robot Framework : Lord of the Rings By Asheesh M
Robot Framework : Lord of the Rings By Asheesh MRobot Framework : Lord of the Rings By Asheesh M
Robot Framework : Lord of the Rings By Asheesh M
Agile Testing Alliance
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
Somkiat Puisungnoen
 
Robot framework - Lord of the Rings
Robot framework - Lord of the RingsRobot framework - Lord of the Rings
Robot framework - Lord of the Rings
Asheesh Mehdiratta
 
Solving cross cutting concerns in PHP - PHPSerbia-2017
Solving cross cutting concerns in PHP - PHPSerbia-2017Solving cross cutting concerns in PHP - PHPSerbia-2017
Solving cross cutting concerns in PHP - PHPSerbia-2017
Alexander Lisachenko
 
Efficient mobile automation
Efficient mobile automationEfficient mobile automation
Efficient mobile automation
Vitaly Tatarinov
 
Robot framework Gowthami Goli
Robot framework Gowthami GoliRobot framework Gowthami Goli
Robot framework Gowthami Goli
Gowthami Buddi
 
Specs2 3.0
Specs2 3.0Specs2 3.0
Specs2 3.0
specs2
 
Acceptance Test Drive Development with Robot Framework
Acceptance Test Drive Development with Robot FrameworkAcceptance Test Drive Development with Robot Framework
Acceptance Test Drive Development with Robot Framework
Ramdhan Hidayat
 
Javascript unit tests with angular 1.x
Javascript unit tests with angular 1.xJavascript unit tests with angular 1.x
Javascript unit tests with angular 1.x
Ron Apelbaum
 
Test automation design patterns
Test automation design patternsTest automation design patterns
Test automation design patterns
Vitaly Tatarinov
 
Robot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs IntegrationRobot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs Integration
Sauce Labs
 
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
OdessaJS Conf
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – Exove
Exove
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5
Jimmy Lu
 
Eclipse Testing Day 2010. Xored Q7
Eclipse Testing Day 2010. Xored Q7Eclipse Testing Day 2010. Xored Q7
Eclipse Testing Day 2010. Xored Q7
platoff
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
Carl Su
 
Introduction to robot framework
Introduction to robot frameworkIntroduction to robot framework
Introduction to robot framework
Chonlasith Jucksriporn
 
利用 Appium + Robot Framework 實現跨平台 App 互動測試
利用 Appium + Robot Framework 實現跨平台 App 互動測試利用 Appium + Robot Framework 實現跨平台 App 互動測試
利用 Appium + Robot Framework 實現跨平台 App 互動測試
Jeremy Kao
 
Head first android apps dev tools
Head first android apps dev toolsHead first android apps dev tools
Head first android apps dev tools
Shaka Huang
 

What's hot (20)

Functional Tests Automation with Robot Framework
Functional Tests Automation with Robot FrameworkFunctional Tests Automation with Robot Framework
Functional Tests Automation with Robot Framework
 
Robot Framework : Lord of the Rings By Asheesh M
Robot Framework : Lord of the Rings By Asheesh MRobot Framework : Lord of the Rings By Asheesh M
Robot Framework : Lord of the Rings By Asheesh M
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
Robot framework - Lord of the Rings
Robot framework - Lord of the RingsRobot framework - Lord of the Rings
Robot framework - Lord of the Rings
 
Solving cross cutting concerns in PHP - PHPSerbia-2017
Solving cross cutting concerns in PHP - PHPSerbia-2017Solving cross cutting concerns in PHP - PHPSerbia-2017
Solving cross cutting concerns in PHP - PHPSerbia-2017
 
Efficient mobile automation
Efficient mobile automationEfficient mobile automation
Efficient mobile automation
 
Robot framework Gowthami Goli
Robot framework Gowthami GoliRobot framework Gowthami Goli
Robot framework Gowthami Goli
 
Specs2 3.0
Specs2 3.0Specs2 3.0
Specs2 3.0
 
Acceptance Test Drive Development with Robot Framework
Acceptance Test Drive Development with Robot FrameworkAcceptance Test Drive Development with Robot Framework
Acceptance Test Drive Development with Robot Framework
 
Javascript unit tests with angular 1.x
Javascript unit tests with angular 1.xJavascript unit tests with angular 1.x
Javascript unit tests with angular 1.x
 
Test automation design patterns
Test automation design patternsTest automation design patterns
Test automation design patterns
 
Robot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs IntegrationRobot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs Integration
 
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – Exove
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5
 
Eclipse Testing Day 2010. Xored Q7
Eclipse Testing Day 2010. Xored Q7Eclipse Testing Day 2010. Xored Q7
Eclipse Testing Day 2010. Xored Q7
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
Introduction to robot framework
Introduction to robot frameworkIntroduction to robot framework
Introduction to robot framework
 
利用 Appium + Robot Framework 實現跨平台 App 互動測試
利用 Appium + Robot Framework 實現跨平台 App 互動測試利用 Appium + Robot Framework 實現跨平台 App 互動測試
利用 Appium + Robot Framework 實現跨平台 App 互動測試
 
Head first android apps dev tools
Head first android apps dev toolsHead first android apps dev tools
Head first android apps dev tools
 

Viewers also liked

Aspect Oriented Programming (AOP) - A case study in Android
Aspect Oriented Programming (AOP) - A case study in AndroidAspect Oriented Programming (AOP) - A case study in Android
Aspect Oriented Programming (AOP) - A case study in Android
Carlos Anjos
 
Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)
Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)
Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)
WSO2
 
ProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and TricksProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and Tricks
netomi
 
Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...
Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...
Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...
CICMoficial
 
Programación Orientada a Aspectos (POA)
Programación Orientada a Aspectos (POA)Programación Orientada a Aspectos (POA)
Programación Orientada a Aspectos (POA)
Walter Javier Franck
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
Jay Kumarr
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershell
Matt Wrock
 
Software Design patterns on Android English
Software Design patterns on Android EnglishSoftware Design patterns on Android English
Software Design patterns on Android English
Pedro Vicente Gómez Sánchez
 

Viewers also liked (8)

Aspect Oriented Programming (AOP) - A case study in Android
Aspect Oriented Programming (AOP) - A case study in AndroidAspect Oriented Programming (AOP) - A case study in Android
Aspect Oriented Programming (AOP) - A case study in Android
 
Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)
Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)
Integrating MQ Protocols with WSO2 ESB 4.9.0 (RabbitMQ, MQTT, Kafka)
 
ProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and TricksProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and Tricks
 
Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...
Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...
Retos del Egresado de Ingeniería Civil ante el paradigma de la sustentabilida...
 
Programación Orientada a Aspectos (POA)
Programación Orientada a Aspectos (POA)Programación Orientada a Aspectos (POA)
Programación Orientada a Aspectos (POA)
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
 
Unit testing powershell
Unit testing powershellUnit testing powershell
Unit testing powershell
 
Software Design patterns on Android English
Software Design patterns on Android EnglishSoftware Design patterns on Android English
Software Design patterns on Android English
 

Similar to AOP on Android

Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
CocoaHeads France
 
Python testing like a pro by Keith Yang
Python testing like a pro by Keith YangPython testing like a pro by Keith Yang
Python testing like a pro by Keith Yang
PYCON MY PLT
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
Michael Vorburger
 
Scaffolding with JMock
Scaffolding with JMockScaffolding with JMock
Scaffolding with JMock
Valerio Maggio
 
UML for Aspect Oriented Design
UML for Aspect Oriented DesignUML for Aspect Oriented Design
UML for Aspect Oriented Design
Edison Lascano
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
Michael Redlich
 
Java Micro-Benchmarking
Java Micro-BenchmarkingJava Micro-Benchmarking
Java Micro-Benchmarking
Constantine Nosovsky
 
Getting started with C++
Getting started with C++Getting started with C++
Getting started with C++
Michael Redlich
 
Building modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf FildebrandtBuilding modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf Fildebrandt
mfrancis
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
Amir Kost
 
A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)
Markus Günther
 
Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!
Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!
Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!
Noopur Gupta
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
Skillwise Group
 
Advanced debugging
Advanced debuggingAdvanced debugging
Advanced debugging
Ali Akhtar
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
Ortus Solutions, Corp
 
Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015
Christian Peel
 
DelOps vs. DevOps
DelOps vs. DevOpsDelOps vs. DevOps
DelOps vs. DevOps
Michael S. Santos M.
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
JiandSon
 
Spring AOP
Spring AOPSpring AOP
Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...
Lucas Leong
 

Similar to AOP on Android (20)

Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
 
Python testing like a pro by Keith Yang
Python testing like a pro by Keith YangPython testing like a pro by Keith Yang
Python testing like a pro by Keith Yang
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
 
Scaffolding with JMock
Scaffolding with JMockScaffolding with JMock
Scaffolding with JMock
 
UML for Aspect Oriented Design
UML for Aspect Oriented DesignUML for Aspect Oriented Design
UML for Aspect Oriented Design
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
Java Micro-Benchmarking
Java Micro-BenchmarkingJava Micro-Benchmarking
Java Micro-Benchmarking
 
Getting started with C++
Getting started with C++Getting started with C++
Getting started with C++
 
Building modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf FildebrandtBuilding modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf Fildebrandt
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)
 
Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!
Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!
Unleashing the Java Tooling in Eclipse IDE - Tips & Tricks!
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
 
Advanced debugging
Advanced debuggingAdvanced debugging
Advanced debugging
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015
 
DelOps vs. DevOps
DelOps vs. DevOpsDelOps vs. DevOps
DelOps vs. DevOps
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...
 

Recently uploaded

Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 

Recently uploaded (20)

Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 

AOP on Android

  • 1. Aspect-oriented programming The next level of abstraction on Android Tibor Šrámek AUGUST 26, 2015
  • 2. 2CONFIDENTIAL Topics Cross-cutting concerns1 Separation of cross-cutting concerns2 Basics of aspect-oriented programming3 AspectJ4 Examples5
  • 4. 4CONFIDENTIAL Cross-cutting concerns Module 1 Module 3 Module 2 Event Tracking Caching Logging Error tracking Event tracking 2 Event tracking 3 Module 4 Imagine a simple system
  • 5. 5CONFIDENTIAL Cross-cutting concerns Module 1 Module 2 Module 3 Module 4 Module 5 original functionality functionality 1 functionality 2 functionality 3 functionality 4 functionality 5 functionality 6 functionality 7 Tangled & redundant code
  • 7. 7CONFIDENTIAL What is AOP? Module 1 Module 2 Module 3 Module 4 Module 5 original functionality functionality 1 functionality 2 functionality 3 functionality 4 functionality 5 functionality 6 functionality 7
  • 8. 8CONFIDENTIAL What is AOP? Modules in one layer CCCs in a separate layer extracted from the original modules (AOP is the glue)
  • 9. 9CONFIDENTIAL What is AOP? •AOP is an extension of OOP •It increases modularity by the separation of CCCs •Decreases code redundancy •Adds functionality using injection without modifying the original code •Besides CCC separation it gives us power…
  • 11. 11CONFIDENTIAL What is AspectJ? •It’s an AOP extension for Java •Very powerful •Easy to learn and use •Java code is valid AspectJ code •AspectJ = Java + some magic
  • 12. 12CONFIDENTIAL AOP terminology •Advice - injected code •Join point - a point of execution •Pointcut - point of injection (set of JPs) •Aspect - advice + pointcut •Weaving - process of injection
  • 13. 13CONFIDENTIAL Weaving Weaving can be static (compile-time) or dynamic (runtime)
  • 14. 14CONFIDENTIAL Android integration // build.gradle apply plugin: 'android-aspectj' buildscript { dependencies { classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.12' } } // an annotation style AspectJ example aspect @Aspect public class LoggerAspect { @Before("call(* MyClass.myMethod())") public void onMyMethodCalled() { Logger.log("My method is called."); } }
  • 15. 15CONFIDENTIAL Advice types •Before code will be injected before the given join point •After code will be injected after the given join point •Around code will be injected instead of the given join point • AfterReturning, AfterThrowing @Before("myPointcut()") public void myAdvice() { // do something here, e.g. null-guarding } @After("call(int *.*View+.get*(..))") public void myAdvice(JoinPoint joinPoint) { // A JoinPoint object contains information about the execution context(method signature, arguments, containing class, etc.) } @Around("myPointcut1() && !myPointCut2()") public void myAdvice(ProceedingJoinPoint point) { // Pre processing work.. point.proceed(); // Post processing work.. // Around is perfect e.g. to skip a method if a parameter is null or to replace a buggy method in a library }
  • 16. 16CONFIDENTIAL Pointcuts •Method: call() & execution() •Constructor: call() & execution() •Field access: get() & set() "execution(* *.myMethod(..))" "call(private MyType.new(..))" "get(String MyClass.name)" Signature: <modifiers> <return_value> <type>.<method_name>(parameter_list) Signature: <modifiers> <class_type>.new(<parameter_list>) Signature: <field_type> <class_type>.<field_name>
  • 17. 17CONFIDENTIAL Advanced pointcuts •Class initialization •Object initialization •Advice execution •Exception handling •Annotations •Etc. (virtually any point in the execution)
  • 18. 18CONFIDENTIAL Aspects Aspects can: •contain regular fields & methods (e.g. for counting) •track private fields & methods (don’t have to break encapsulation) •inherit from other aspects (e.g. for reusing advices)
  • 19. 19CONFIDENTIAL Aspects Aspects also can: •be inner classes •be instantiated •declare advice execution order •implement inter-type declarations
  • 21. 21CONFIDENTIAL Common applications of AOP •Logging •Tracking (event, error, performance) •Persistence •Validation •Synchronization •Security
  • 22. 22CONFIDENTIAL AspectJ Is it good for anything else besides the separation of CCCs? •Skip or replace methods •Prevent or handle errors •Dependency injection •Separation of architectural layers
  • 23. 23CONFIDENTIAL Dependency injection with AOP Consider Dagger, if you want to satisfy a dependency you have to: •make a module •make a component •modify the dependent class
  • 24. 24CONFIDENTIAL Dependency injection with AOP With AOP you only have to do this: @Aspect class DependencyInjector { @After("execution(Dependent.new(..))") public void inject(JoinPoint p) { Dependent dependent = (Dependent) p.getThis(); dependent.dependency = new Dependency(); } }
  • 25. 25CONFIDENTIAL Architecture with AOP Imagine a simple architecture @Aspect public class MyAspect { private MyView view; private MyPresenter presenter; private MyProvider provider; @After("execution(MyView.onCreate(..))") private void init(JoinPoint jp) { view = (MyView) jp.getThis(); presenter = new MyPresenter(); provider = new MyProvider(); } @After("execution(MyView.myButtonClicked(..))") private void myButtonClicked() { presenter.createRequest(); } @AfterReturning(pointcut = "execution(MyPresenter.createRequest(..))", returning = "request") private void requestCreated(Request request) { provider.sendRequest(request); } @After("execution(MyProvider.onResponse(..))") private void responseArrived(JoinPoint jp) { String result = presenter.processResponse((Response) jp.getArgs()[0]); view.showResult(result); } }
  • 26. 26CONFIDENTIAL Architecture with AOP A system like this is: •Modular (e.g. multiple presenters for a view) •Flexible (e.g. don’t have to use interfaces) •Easy to test (don’t have to mock anything, test only what you want)
  • 27. 27CONFIDENTIAL Tips & tricks You have to implement something • that probably will be removed in the future? Put it to an aspect! You will have to just delete the aspect. • for only one build variant? Put it to an aspect in that variant! In many cases you will have to implement only the differences. Unleash your imagination… (but don’t try to build the whole system with aspects)
  • 29. 29CONFIDENTIAL AOP supported languages • Java • Objective-C • .NET (C# / VB.NET) • C / C++ • Python • Perl • PHP • JavaScript • Groovy • Ruby • ActionScript • Ada • AutoHotkey • COBOL • ColdFusion • Lisp • Delphi • Haskell • Logtalk • Lua • Matlab • Prolog • Racket • Smalltalk • Etc.
  • 30. 30CONFIDENTIAL Active users of AOP •Microsoft •Oracle •IBM •SAP •Siemens •Red Hat •Epam There is a whole paradigm called Aspect-oriented software development…
  • 31. 31CONFIDENTIAL Useful links • http://www.eclipse.org/aspectj • http://fernandocejas.com/2014/08/03/aspect-oriented-programming-in-android • https://github.com/uPhyca/gradle-android-aspectj-plugin • https://www.youtube.com/watch?v=cq7wpLI0hco • Google is your friend 
  • 32. 32CONFIDENTIAL Literature • Robert E. Filman, Tzilla Elrad, Siobhan Clarke, Mehmet Aksit: Aspect-Oriented Software Development. Addison-Wesley Professional, October 2004, 800 pp. ISBN: 0321219767. • Renaud Pawlak, Jean-Philippe Retaillé, Lionel Seinturier: Foundations of AOP for J2EE Development. Apress, September 2005, 352 pp. ISBN: 1590595076. • Ramnivas Laddad: AspectJ in Action: Practical Aspect-Oriented Programming. Manning Publications, July 2003, 512 pp. ISBN: 1930110936. • Siobhan Clarke, Elisa Baniassad: Aspect-Oriented Analysis and Design: The Theme Approach. Addison-Wesley Professional, March 2005, 400 pp. ISBN: 0321246748. • Ivar Jacobson, Pan-Wei Ng: Aspect-Oriented Software Development with Use Cases. Addison-Wesley Professional, December 2004, 464 pp. ISBN: 0321268881. • Joseph D. Gradecki, Nicholas Lesiecki: Mastering AspectJ: Aspect-Oriented Programming in Java. Wiley, April 2003, 456 pp. ISBN: 0471431044. • Russell Miles: Aspectj Cookbook. O'Reilly Media, December 2004, 331 pp. ISBN: 0596006543.

Editor's Notes

  1. Presenter: Tibor Šrámek (tibor_sramek@epam.com)
  2. AOP is a huge topic. This is just a quick teaser but at the end You will be able to use it and see if it’s worth to try.
  3. Connections between modules and functionalities can get out of hand really fast.
  4. CCCs are functionalities spreading all over a system (with modules which are heavily dependent and hard to test). They undermine the Single Responsibility Principle and increase code redundancy.
  5. This is AOP in one picture. A system like this would make work easier. But how to achieve it?
  6. AOP was made for CCC separation but that doesn’t mean it’s not good for other things. Enum wasn’t made for singleton creation, but what if You have to make a thread-safe singleton?
  7. Let’s see an AOP implementation
  8. We want to see clean modules. Let the machines work with tangled code. Static weaving is the most common and the fastest.
  9. Integration and example on one page. AspectJ is an Eclipse Foundation product. Eclipse users can use keywords instead of annotations and they don’t have to write strings. But this style isn’t bad either and there can be a similar plugin for the Android Studio in the future.
  10. AfterReturning gives us the returned object and AfterThrowing the thrown exception. * - any characters except the ‘.’ .. – any characters including the ‘.’ + - any subclasses or subinterfaces
  11. With constructor pointcuts You can e.g. implement dependency injection. With field access pointcuts You can e.g. implement field validation.
  12. Annotations are handy if You can’t fine common things in join points.
  13. If we mess something up the error manifests during the compilation
  14. If we mess something up the error manifests during the compilation. Virtually we can inject anything and anywhere.
  15. You can also define injections for field accesses. Build time is faster than with Dagger.
  16. If modules don’t know about each other they are not depending on each other
  17. I hope You are interested….
  18. Mainstream languages have AOP support
  19. The official documentation, a good Android-AOP tutorial, the plugin’s repo and an interesting presentation by Gregor Kiczales (one of the fathers of AOP) There are tons of AOP blogs and tutorials on the web
  20. If someone likes to read from paper….
  21. Presenter: Tibor Šrámek (tibor_sramek@epam.com)