SlideShare una empresa de Scribd logo
1 de 23
AOP med AspectJ
                    - en introduktion


                     Mattias Jiderhamn


Mattias Jiderhamn
Om talaren
@author AspectJ weaver plugin för IntelliJ IDEA




  ! (this instanceof AspectJWizard)




Mattias Jiderhamn
Kort historik
                AspectJ (2001)
                           AspectWerkz (2002)




             AspectJ 1.5 (2005)
Mattias Jiderhamn
Hög tröskel
  Recept för AOP:
  1 del Mumbo Jumbo
  1 del Hokus Pokus


          Recipie for
          disaster…?


Mattias Jiderhamn
Mumbo Jumbo
  •   Cross-cutting concern
  •   Join point
  •   Pointcut
  •   Advice
  •   Aspect
  •   Weaving
  •   Inter-type declaration
  •   Mixin
  •   cflow
Mattias Jiderhamn
Cross-cutting concern
     Behov som går på tvären igenom
      flera lager och/eller moduler.
  Exempel:
  •Loggning
  •Auktorisering
  •Transaktioner
  •Datavalidering


Mattias Jiderhamn
Join point
           Punkter där det är möjligt
               att applicera ett
             cross-cutting concern

  AOP LINE - DO CROSS   AOP LINE - DO CROSS


  Exempel: metodanrop
Mattias Jiderhamn
Cross-cutting concern

                    Loggning Behörighet Transaktioner

   Artikel
   modul
                                                 Join point

Kund-modul

Data-access

  REST API

Mattias Jiderhamn
Pointcut
    Deklarationen av en join point.
   Definierar var skall något hända.
      Tillåter ofta kombinationer
            av flera join points.
Exempel: ”när metoden B.a() anropas
   ELLER exceptionet Foo fångas i
   klassen Bar”
Mattias Jiderhamn
Advice
                    Implementationen av ett
                      cross-cutting concern

                        Vad skall hända



Mattias Jiderhamn
Aspect
                    Modul innehållande
                    pointcuts och advice

                         Var + Vad



Mattias Jiderhamn
Weaving
        Processen när advice appliceras
                    på angivna pointcuts
                                  ”Advised”

    Klass A          Weaving        Klass A’

Mattias Jiderhamn
Inter-type declaration
  Lägg till deklarationer till en eller flera
  (redan kompilerade) klasser
  •Fält
  •Metoder
  •Konstruktorer
  •Interface
  •Bas-klasser (”multipelt arv”)
Mattias Jiderhamn
Mixin
Förenklat: Annat namn på inter-type
  declarations (från AspectWerkz)




Mattias Jiderhamn
cflow




Mattias Jiderhamn
Hokus Pokus
  • Älskar Java och Open Source pga
    avsaknaden av Hokus Pokus
  • Få undantag (serialization)
  • AOP innebär Hokus Pokus…




Mattias Jiderhamn
Fyra metoder
  • Proxy + InvocationHandler
  • CGLIB

  • java.lang.instrument + -javaagent
  • Compile time weaving (”riktig AOP”)




Mattias Jiderhamn
Två syntaxer
  • .aj (AspectJ)
  • Annoteringar (AspectWerkz)




Mattias Jiderhamn
.aj
  aspect Logging {

      pointcut pc() : execution(public
        static void main(String[]));

      before() : pc() {
        System.out.println(”foo");
      }
  }

Mattias Jiderhamn
Demo




Mattias Jiderhamn
call() vs execution()
                    call()


class A {                              class B {
  void a() {                             void b() {
    b.b();                                 ...
  }                                      }
}                                      }
                         execution()

Mattias Jiderhamn
Avslutande råd
  • AOP + TDD = sant
  • Använd AOP med måtta




Mattias Jiderhamn
Länkar
  http://eclipse.org/aspectj
  http://java.jiderhamn.se
  https://github.com/mjiderhamn/aspectj-intro


                     Frågor?

Mattias Jiderhamn

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Introduktion till Aspekt-orienterad programmering (AOP) med AspectJ

  • 1. AOP med AspectJ - en introduktion Mattias Jiderhamn Mattias Jiderhamn
  • 2. Om talaren @author AspectJ weaver plugin för IntelliJ IDEA ! (this instanceof AspectJWizard) Mattias Jiderhamn
  • 3. Kort historik AspectJ (2001) AspectWerkz (2002) AspectJ 1.5 (2005) Mattias Jiderhamn
  • 4. Hög tröskel Recept för AOP: 1 del Mumbo Jumbo 1 del Hokus Pokus Recipie for disaster…? Mattias Jiderhamn
  • 5. Mumbo Jumbo • Cross-cutting concern • Join point • Pointcut • Advice • Aspect • Weaving • Inter-type declaration • Mixin • cflow Mattias Jiderhamn
  • 6. Cross-cutting concern Behov som går på tvären igenom flera lager och/eller moduler. Exempel: •Loggning •Auktorisering •Transaktioner •Datavalidering Mattias Jiderhamn
  • 7. Join point Punkter där det är möjligt att applicera ett cross-cutting concern AOP LINE - DO CROSS AOP LINE - DO CROSS Exempel: metodanrop Mattias Jiderhamn
  • 8. Cross-cutting concern Loggning Behörighet Transaktioner Artikel modul Join point Kund-modul Data-access REST API Mattias Jiderhamn
  • 9. Pointcut Deklarationen av en join point. Definierar var skall något hända. Tillåter ofta kombinationer av flera join points. Exempel: ”när metoden B.a() anropas ELLER exceptionet Foo fångas i klassen Bar” Mattias Jiderhamn
  • 10. Advice Implementationen av ett cross-cutting concern Vad skall hända Mattias Jiderhamn
  • 11. Aspect Modul innehållande pointcuts och advice Var + Vad Mattias Jiderhamn
  • 12. Weaving Processen när advice appliceras på angivna pointcuts ”Advised” Klass A Weaving Klass A’ Mattias Jiderhamn
  • 13. Inter-type declaration Lägg till deklarationer till en eller flera (redan kompilerade) klasser •Fält •Metoder •Konstruktorer •Interface •Bas-klasser (”multipelt arv”) Mattias Jiderhamn
  • 14. Mixin Förenklat: Annat namn på inter-type declarations (från AspectWerkz) Mattias Jiderhamn
  • 16. Hokus Pokus • Älskar Java och Open Source pga avsaknaden av Hokus Pokus • Få undantag (serialization) • AOP innebär Hokus Pokus… Mattias Jiderhamn
  • 17. Fyra metoder • Proxy + InvocationHandler • CGLIB • java.lang.instrument + -javaagent • Compile time weaving (”riktig AOP”) Mattias Jiderhamn
  • 18. Två syntaxer • .aj (AspectJ) • Annoteringar (AspectWerkz) Mattias Jiderhamn
  • 19. .aj aspect Logging { pointcut pc() : execution(public static void main(String[])); before() : pc() { System.out.println(”foo"); } } Mattias Jiderhamn
  • 21. call() vs execution() call() class A { class B { void a() { void b() { b.b(); ... } } } } execution() Mattias Jiderhamn
  • 22. Avslutande råd • AOP + TDD = sant • Använd AOP med måtta Mattias Jiderhamn
  • 23. Länkar http://eclipse.org/aspectj http://java.jiderhamn.se https://github.com/mjiderhamn/aspectj-intro Frågor? Mattias Jiderhamn