SlideShare a Scribd company logo
@magma_digital
Code All the Things
An introduction to Aspect–Oriented Programming
@magma_digital
Who am I?
๏ Jeremy Coates, CEO, Magma Digital Ltd
๏ Founder of PHPNW User Group & Conference
๏ Digital Lancashire CIC Founding Director
๏ International Conference Speaker
๏ Coach of Coaches - WeCa.mp (code camp)
๏ @phpcodemonkey
๏ linkedin.com/in/jeremycoates
@magma_digital
★ Aspect–Oriented Programming - using Go! AOP
• Separate cross-cutting concerns (logging, caching etc.) into
Aspects (aka. a class that implements Aspect)
• Adds behaviour without modifying code itself - Advice (can
be an annotation e.g. @Around, @Before or @After)
• An approach to specify where to apply an Advice - Pointcut
(regex matching) / Join Points (a script execution point e.g.
method)
Aspect–Oriented What?
@magma_digital
★ Concerns like logging, security, caching
• Don’t neatly fit traditional OOP models
• They cut across concerns and litter our code
• $logger->info(‘message’);
• $perm->hasPriv(‘admin’);
OOP but not as we know it
@magma_digital
★ Regular classes that bundle functionality
• Like logging, caching, security etc.
• Use annotations to trigger method invocation
• @Before(“@execution(MagmaDigitalAnnotatio
nLoggable)”)
• @Before("execution(public Example->*(*))")
Aspect
@magma_digital
★ A conceptual term indicating a point during the
execution of a script e.g.
• Method or
• Property Access
Join Point
@magma_digital
★ Action taken by an Aspect at a given Join Point - Identified by
an annotation
• @Before - executes before the Join Point
• @After / @AfterThrowing - Executes after the Join Point
exits
• @Around - surrounds the Join Point
• Custom behaviour before & after, can also prevent
continued execution, return own value/exception etc.
@Advice
@magma_digital
★ Simply a regular expression that matches join points
• An Advice is linked to the Pointcut and runs at any
Join Point matched by the regex
• e.g. methods matching a certain name stub
• @Pointcut("@execution(MagmaDigital
AnnotationLoggableDetailed)")
Pointcut
@magma_digital
★ Framework depends on autoloading
• Really old legacy code needs converting first
★ composer require goaop/framework
★ Create application AspectKernel
★ Configure AspectKernel
★ Create an Aspect class (& Register in AspectKernel)
Go! AOP
First 10 Minutes
@magma_digital
★ Aspect–Oriented Programming can also
• Introduce new interfaces / traits (inter-type
declaration)
• e.g. make all DTOs implement Serializable
• Weave code - link to other applications/objects
• e.g. Doctrine Entities
Advanced Use
@magma_digital
★ PHPStorm - Go! AOP Framework plugin
• also needs PHP Annotations Plugin
★ Frameworks
• goaop-laravel-bridge
• goaop-symfony-bundle
• goaop-zf2-module
Support
@magma_digital
★ Codeception/AspectMock (github)
• Based on Go! AOP
• Create test doubles for static methods
• Create test doubles for class methods (wherever
they’re called)
• Redefine (PHP or user)methods on the fly
Aspect–Oriented Testing
@magma_digital
★ http://go.aopphp.com/docs/
★ https://packagist.org/packages/goaop/framework
★ https://github.com/goaop/framework
• https://github.com/goaop
★ https://github.com/Codeception/AspectMock
Resources

More Related Content

KEY
Clip to evernote
Akira Sawada
 
PPTX
Custom elements
Ran Wahle
 
PPT
Web development basics (Part-3)
Rajat Pratap Singh
 
PDF
Introduction to Scala for Java Developers
Solix JJ
 
PPTX
Intro cujojs
Yubin Yang
 
ODP
How to add Fixtures into your Django app with Mixer
Guinsly Mondesir
 
PPTX
Simple introduction about cordova
ahmed wahba
 
PPTX
Modern java script features
Kunal Kursija
 
Clip to evernote
Akira Sawada
 
Custom elements
Ran Wahle
 
Web development basics (Part-3)
Rajat Pratap Singh
 
Introduction to Scala for Java Developers
Solix JJ
 
Intro cujojs
Yubin Yang
 
How to add Fixtures into your Django app with Mixer
Guinsly Mondesir
 
Simple introduction about cordova
ahmed wahba
 
Modern java script features
Kunal Kursija
 

Similar to Aspect Oriented Programming (20)

PDF
Stackato v6
Jonas Brømsø
 
PDF
Stackato v4
Jonas Brømsø
 
PDF
Stackato v3
Jonas Brømsø
 
PPTX
Letest
Prakash Poudel
 
PPTX
Java Programming concept
Prakash Poudel
 
PPT
Scala io2013 : Our journey from UML/MDD to Scala macros
ebiznext
 
PDF
Introduction to Micronaut - JBCNConf 2019
graemerocher
 
PDF
Building and deploying AI agents in Java
Buhake Sindi
 
PPTX
How I Learned to Stop Worrying and Love Legacy Code.....
Mike Harris
 
PDF
Stackato v2
Jonas Brømsø
 
PPTX
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
PDF
Stackato v5
Jonas Brømsø
 
PPTX
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
PPTX
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
PDF
Stackato
Jonas Brømsø
 
PDF
The Diabolical Developers Guide to Performance Tuning
jClarity
 
PDF
Angular SEO
Tiang Cheng
 
PDF
Integrating Existing C++ Libraries into PySpark with Esther Kundin
Databricks
 
PPTX
04 managing the database
Марина Босова
 
PPTX
Data Science Salon: A Journey of Deploying a Data Science Engine to Production
Formulatedby
 
Stackato v6
Jonas Brømsø
 
Stackato v4
Jonas Brømsø
 
Stackato v3
Jonas Brømsø
 
Java Programming concept
Prakash Poudel
 
Scala io2013 : Our journey from UML/MDD to Scala macros
ebiznext
 
Introduction to Micronaut - JBCNConf 2019
graemerocher
 
Building and deploying AI agents in Java
Buhake Sindi
 
How I Learned to Stop Worrying and Love Legacy Code.....
Mike Harris
 
Stackato v2
Jonas Brømsø
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
Stackato v5
Jonas Brømsø
 
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Stackato
Jonas Brømsø
 
The Diabolical Developers Guide to Performance Tuning
jClarity
 
Angular SEO
Tiang Cheng
 
Integrating Existing C++ Libraries into PySpark with Esther Kundin
Databricks
 
04 managing the database
Марина Босова
 
Data Science Salon: A Journey of Deploying a Data Science Engine to Production
Formulatedby
 
Ad

More from Jeremy Coates (17)

PPTX
Cyber Security and GDPR
Jeremy Coates
 
PDF
Why is PHP Awesome
Jeremy Coates
 
PDF
Testing with Codeception
Jeremy Coates
 
KEY
An introduction to Phing the PHP build system (PHPDay, May 2012)
Jeremy Coates
 
KEY
An introduction to Phing the PHP build system
Jeremy Coates
 
KEY
Insects in your mind
Jeremy Coates
 
KEY
Phing
Jeremy Coates
 
KEY
Hudson Continuous Integration for PHP
Jeremy Coates
 
PDF
The Uncertainty Principle
Jeremy Coates
 
PPT
Exploiting Php With Php
Jeremy Coates
 
ODP
What's new, what's hot in PHP 5.3
Jeremy Coates
 
PDF
Kiss Phpnw08
Jeremy Coates
 
PPT
Regex Basics
Jeremy Coates
 
ODP
Search Lucene
Jeremy Coates
 
PDF
Mysql Explain Explained
Jeremy Coates
 
ODP
Introduction to Version Control
Jeremy Coates
 
ODP
PHPNW Conference Update
Jeremy Coates
 
Cyber Security and GDPR
Jeremy Coates
 
Why is PHP Awesome
Jeremy Coates
 
Testing with Codeception
Jeremy Coates
 
An introduction to Phing the PHP build system (PHPDay, May 2012)
Jeremy Coates
 
An introduction to Phing the PHP build system
Jeremy Coates
 
Insects in your mind
Jeremy Coates
 
Hudson Continuous Integration for PHP
Jeremy Coates
 
The Uncertainty Principle
Jeremy Coates
 
Exploiting Php With Php
Jeremy Coates
 
What's new, what's hot in PHP 5.3
Jeremy Coates
 
Kiss Phpnw08
Jeremy Coates
 
Regex Basics
Jeremy Coates
 
Search Lucene
Jeremy Coates
 
Mysql Explain Explained
Jeremy Coates
 
Introduction to Version Control
Jeremy Coates
 
PHPNW Conference Update
Jeremy Coates
 
Ad

Recently uploaded (20)

PPTX
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PPTX
AZ900_SLA_Pricing_2025_LondonIT (1).pptx
chumairabdullahph
 
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PPTX
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPT
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
AZ900_SLA_Pricing_2025_LondonIT (1).pptx
chumairabdullahph
 
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
oapresentation.pptx
mehatdhavalrajubhai
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 

Aspect Oriented Programming

  • 1. @magma_digital Code All the Things An introduction to Aspect–Oriented Programming
  • 2. @magma_digital Who am I? ๏ Jeremy Coates, CEO, Magma Digital Ltd ๏ Founder of PHPNW User Group & Conference ๏ Digital Lancashire CIC Founding Director ๏ International Conference Speaker ๏ Coach of Coaches - WeCa.mp (code camp) ๏ @phpcodemonkey ๏ linkedin.com/in/jeremycoates
  • 3. @magma_digital ★ Aspect–Oriented Programming - using Go! AOP • Separate cross-cutting concerns (logging, caching etc.) into Aspects (aka. a class that implements Aspect) • Adds behaviour without modifying code itself - Advice (can be an annotation e.g. @Around, @Before or @After) • An approach to specify where to apply an Advice - Pointcut (regex matching) / Join Points (a script execution point e.g. method) Aspect–Oriented What?
  • 4. @magma_digital ★ Concerns like logging, security, caching • Don’t neatly fit traditional OOP models • They cut across concerns and litter our code • $logger->info(‘message’); • $perm->hasPriv(‘admin’); OOP but not as we know it
  • 5. @magma_digital ★ Regular classes that bundle functionality • Like logging, caching, security etc. • Use annotations to trigger method invocation • @Before(“@execution(MagmaDigitalAnnotatio nLoggable)”) • @Before("execution(public Example->*(*))") Aspect
  • 6. @magma_digital ★ A conceptual term indicating a point during the execution of a script e.g. • Method or • Property Access Join Point
  • 7. @magma_digital ★ Action taken by an Aspect at a given Join Point - Identified by an annotation • @Before - executes before the Join Point • @After / @AfterThrowing - Executes after the Join Point exits • @Around - surrounds the Join Point • Custom behaviour before & after, can also prevent continued execution, return own value/exception etc. @Advice
  • 8. @magma_digital ★ Simply a regular expression that matches join points • An Advice is linked to the Pointcut and runs at any Join Point matched by the regex • e.g. methods matching a certain name stub • @Pointcut("@execution(MagmaDigital AnnotationLoggableDetailed)") Pointcut
  • 9. @magma_digital ★ Framework depends on autoloading • Really old legacy code needs converting first ★ composer require goaop/framework ★ Create application AspectKernel ★ Configure AspectKernel ★ Create an Aspect class (& Register in AspectKernel) Go! AOP First 10 Minutes
  • 10. @magma_digital ★ Aspect–Oriented Programming can also • Introduce new interfaces / traits (inter-type declaration) • e.g. make all DTOs implement Serializable • Weave code - link to other applications/objects • e.g. Doctrine Entities Advanced Use
  • 11. @magma_digital ★ PHPStorm - Go! AOP Framework plugin • also needs PHP Annotations Plugin ★ Frameworks • goaop-laravel-bridge • goaop-symfony-bundle • goaop-zf2-module Support
  • 12. @magma_digital ★ Codeception/AspectMock (github) • Based on Go! AOP • Create test doubles for static methods • Create test doubles for class methods (wherever they’re called) • Redefine (PHP or user)methods on the fly Aspect–Oriented Testing
  • 13. @magma_digital ★ http://go.aopphp.com/docs/ ★ https://packagist.org/packages/goaop/framework ★ https://github.com/goaop/framework • https://github.com/goaop ★ https://github.com/Codeception/AspectMock Resources

Editor's Notes

  • #3: I’ve been a developer for almost 20 years and have long history of consulting, adopting other peoples projects and running kick-ass software agency. For my day job, I am CEO of Magma Digital Ltd, a 20 strong team focussing on delivering business critical software development, using PHP, to enterprise. I am also the driving force behind the UK's PHPNW conference, user group and brand, I started the group in 2008 and have, with assistance from many others, helped the group to be able to deliver seven years of high quality conferences, now with 400+ delegates. The passion for this comes from my personal drive to improve skills in those around me who I serve through mentoring, coaching, training and speaking. Pleasure of attending all but 1 Benelux conference and speaking at PHPBNL 12, 14 and now 16 - seems like even numbered years are my thing!