Introduction to aop

Dror Helper
Dror HelperConsultant & software architect @ Practical Software at CodeValue
Introduction to AOP

Dror Helper
@dhelper
About.Me
   Software developer and technical lead

   PostSharp MVP

   Blogger: http://blog.drorhelper.com
Developer write code
void transfer(Account fromAcc, Account toAcc, int amount)
{
      if (fromAcc.getBalance() < amount)
      {
             throw new InsufficientFundsException();
      }


      fromAcc.withdraw(amount);
      toAcc.deposit(amount);
}
Permission support – Right away!
void transfer(Account fromAcc, Account toAcc, int amount, User user)
{
       if (! checkUserPermission(user))
       {
                throw new UnauthorizedUserException();
       }


       if (fromAcc.getBalance() < amount)
       {
                throw new InsufficientFundsException();
       }


       fromAcc.withdraw(amount);
       toAcc.deposit(amount);
}
Need to check parameters – Done!
void transfer(Account fromAcc, Account toAcc, int amount, User user)
{
          if(fromAcc == null || toAcc == null)
          {
                      throw new IllegalArgumentException ();
          }


          if(balance <= 0)
          {
                      throw new IllegalArgumentException ();
          }


          if (! checkUserPermission(user))
          {
                      throw new UnauthorizedUserException();
          }


          if (fromAcc.getBalance() < amount)
          {
                      throw new InsufficientFundsException();
          }


          fromAcc.withdraw(amount);
          toAcc.deposit(amount);
}
Needs logging – no problems!
void transfer(Account fromAcc, Account toAcc, int amount, User user)
{
        logger.info("transferring money...");
        if(balance <= 0)
        {
                   throw new IllegalArgumentException ();
        }


        if (! checkUserPermission(user))
        {
                  logger.info("User has no permission.");
                  throw new UnauthorizedUserException();
        }


        if (fromAcc.getBalance() < amount)
        {
                  logger.info("Insufficient Funds, sorry");
                  throw new InsufficientFundsException();
        }


        fromAcc.withdraw(amount);
        toAcc.deposit(amount);
And finally – exception handling
void transfer(Account fromAcc, Account toAcc, int amount, User user)
{
             logger.info("transferring money...");
             if(balance <= 0)
             {
                                throw new IllegalArgumentException ();
             }


             if (! checkUserPermission(user))
             {
                            logger.info("User has no permission.");
                            throw new UnauthorizedUserException();
             }


             if (fromAcc.getBalance() < amount)
             {
                            logger.info("Insufficient Funds, sorry");
                            throw new InsufficientFundsException();
             }
             try
             {
                            fromAcc.withdraw(amount);
                            toAcc.deposit(amount);
             }
             catch(Exception exc)
             {
                            logger.info(“failed transaction.");
                            return;
             }
What can we do?
The Problem
   Code duplication

   Hard to read

   Difficult to maintain

   Not all programmers code the same


             Ctrl + C, Ctrl + V
Problem - Cross cutting concerns


                Customer   Product    Order




                           Logging


Cross-Cutting
                           Security
Concerns


                           Caching
Non-Functional Requirements
   Security
   Caching
   Tracing
   Exception handling
   Monitoring
   Validation
   Persistence
   Transactions
   Thread sync
Solution  AOP
    Separation of concerns
    Extension of OOP

1.    Encapsulate Cross cutting concerns into aspects
2.    Apply aspects to code
Why AOP


              • AOP exist for more then 15
   Mature       years

   Industry   • Industry standard
   adopted
  Observed    • -15% lines of code
  Benefits    • -20% decoupling
Terminology
Join Point
static void Main()
{
                                          myClass1.Func1
          var myClass1 = new MyClass();

          var myClass2 = new MyClass();



          myClass1.Func1();
          myClass1.Func2(2, 3);
                                          myClass1.Func2
          myClass2.Func2(4, 5);
}




                                          myClass2.Func2
Point Cuts

             myClass1.Func1




             myClass1.Func2   Before Func2




             myClass2.Func2
Advice
   The code to run
   Typically small
   Injected at join point
Aspect
Join Point + Advice = Aspect
How to “do” AOP
Our example for today – the calculator
My co-worker solution
#1 Functional programming
   Using higher order functions to “warp” existing code
   Decorator pattern
1# Functional Programming

              +                                -
   No additional                  You cannot automatically
    dependency in your              pass context from the
                                    caller to the aspect code
    build or runtime code.
                                   Must modify the code of
   Programmers are                 every method to which
    already familiar with the       you want to add the
    technology.                     aspect.

                                   Aspect composition is less
                                    convenient.
Why not use existing tools
What IoC containers can do for you?
   Enable Dependency Injection (DI)

   Create objects and satisfy it’s dependencies

   A lot more..
#2 Dynamic proxies




                      Framework


Application   Proxy               Aspect   Object
.NET IoC tools
   Unity http://unity.codeplex.com/
   Spring.NET http://www.springframework.net/
   Castle http://www.castleproject.org/
Dynamic proxies

              +                                -
   You may already be           Very limited aspect-oriented
                                  features.
    using a DI framework.
                                 Your objects must be
                                  instantiated using the
   Aspects can be                container
    configured after build.
                                 Does not work on
                                  static, non-public, and/or
   Some aspects may be           non-virtual methods
    provided by the
                                 Does not work on
    framework.                    fields, properties, or events.
#3 MSIL transformations




                       IL        Final
   Code    Compile
                     weaving   Assembly
IL transformation tools
   Mono.Cecil http://www.mono-project.com/Cecil
   NotifyPropertyWeaver
    http://code.google.com/p/notifypropertyweaver/
MSIL transformations

             +                              -
   Very powerful. You can      Requires an advanced
                                 knowledge of MSIL.
    achieve virtually any
    code transformation         Very low level

   These frameworks are        typically do not compose
                                 well when many are
    free of charge and           applied to the same
    backed by large              method.
    companies.
                                No Visual Studio tooling.
#4 Build time AOP


                Build Process
                     Intermediate
                                            Final
Source    Compiler     Assembly     AOP   Assembly
 Code                     (IL)




Aspects
Summery
 Use AOP because:

   Less code = fewer bugs
   Less code = easier to read and maintain
   Reduce duplicate code
   Improve team work/architecture
   Reduce development cost
Resources
Cross Cutting Concerns blog
http://crosscuttingconcerns.com/

My blog: http://blog.drorhelper.com
1 of 34

Recommended

Spring AOP by
Spring AOPSpring AOP
Spring AOPSHAKIL AKHTAR
1.3K views50 slides
Spring AOP Introduction by
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introductionb0ris_1
3.4K views26 slides
Spring AOP in Nutshell by
Spring AOP in Nutshell Spring AOP in Nutshell
Spring AOP in Nutshell Onkar Deshpande
1.8K views22 slides
Reactive Thinking in Java with RxJava2 by
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Yakov Fain
4.7K views77 slides
JavaFX Pitfalls by
JavaFX PitfallsJavaFX Pitfalls
JavaFX PitfallsAlexander Casall
8K views107 slides
Intro to JavaScript by
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptYakov Fain
2K views49 slides

More Related Content

What's hot

Apex 5 plugins for everyone version 2018 by
Apex 5 plugins for everyone   version 2018Apex 5 plugins for everyone   version 2018
Apex 5 plugins for everyone version 2018Alan Arentsen
509 views136 slides
Dart for Java Developers by
Dart for Java DevelopersDart for Java Developers
Dart for Java DevelopersYakov Fain
2.1K views57 slides
Zend Studio Tips and Tricks by
Zend Studio Tips and TricksZend Studio Tips and Tricks
Zend Studio Tips and TricksRoy Ganor
6.8K views25 slides
Test Driven Development with JavaFX by
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
16.5K views64 slides
Living With Legacy Code by
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
25.3K views80 slides
Testing React Applications by
Testing React ApplicationsTesting React Applications
Testing React Applicationsstbaechler
933 views21 slides

What's hot(20)

Apex 5 plugins for everyone version 2018 by Alan Arentsen
Apex 5 plugins for everyone   version 2018Apex 5 plugins for everyone   version 2018
Apex 5 plugins for everyone version 2018
Alan Arentsen509 views
Dart for Java Developers by Yakov Fain
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
Yakov Fain2.1K views
Zend Studio Tips and Tricks by Roy Ganor
Zend Studio Tips and TricksZend Studio Tips and Tricks
Zend Studio Tips and Tricks
Roy Ganor6.8K views
Test Driven Development with JavaFX by Hendrik Ebbers
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers16.5K views
Living With Legacy Code by Rowan Merewood
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood25.3K views
Testing React Applications by stbaechler
Testing React ApplicationsTesting React Applications
Testing React Applications
stbaechler933 views
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing by Tal Melamed
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingJava Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Tal Melamed312 views
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti... by Codemotion
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Codemotion795 views
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ... by Stanfy
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy622 views
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide by Victor Rentea
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Victor Rentea1.6K views
The Art of Unit Testing - Towards a Testable Design by Victor Rentea
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
Victor Rentea2.4K views
JavaOne - The JavaFX Community and Ecosystem by Alexander Casall
JavaOne - The JavaFX Community and EcosystemJavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and Ecosystem
Alexander Casall1.7K views
RESTful services and OAUTH protocol in IoT by Yakov Fain
RESTful services and OAUTH protocol in IoTRESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoT
Yakov Fain4K views
Pharo Optimising JIT Internals by ESUG
Pharo Optimising JIT InternalsPharo Optimising JIT Internals
Pharo Optimising JIT Internals
ESUG925 views
How AngularJS Embraced Traditional Design Patterns by Ran Mizrahi
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
Ran Mizrahi12.4K views
Dependency injection - the right way by Thibaud Desodt
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
Thibaud Desodt23.1K views
How Testability Inspires AngularJS Design / Ran Mizrahi by Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran Mizrahi
Ran Mizrahi716 views

Similar to Introduction to aop

Unit Testing 101 by
Unit Testing 101Unit Testing 101
Unit Testing 101Dave Bouwman
13.5K views89 slides
Aspect-Oriented Programming by
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented ProgrammingAndrey Bratukhin
1.6K views16 slides
Advanced iOS Debbuging (Reloaded) by
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Massimo Oliviero
4.1K views95 slides
Maxim Salnikov - Service Worker: taking the best from the past experience for... by
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Codemotion
193 views78 slides
How and why we evolved a legacy Java web application to Scala... and we are s... by
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...Katia Aresti
1.3K views114 slides
Apex Enterprise Patterns: Building Strong Foundations by
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsSalesforce Developers
12.8K views48 slides

Similar to Introduction to aop(20)

Unit Testing 101 by Dave Bouwman
Unit Testing 101Unit Testing 101
Unit Testing 101
Dave Bouwman13.5K views
Advanced iOS Debbuging (Reloaded) by Massimo Oliviero
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
Massimo Oliviero4.1K views
Maxim Salnikov - Service Worker: taking the best from the past experience for... by Codemotion
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Codemotion193 views
How and why we evolved a legacy Java web application to Scala... and we are s... by Katia Aresti
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...
Katia Aresti1.3K views
Apex Enterprise Patterns: Building Strong Foundations by Salesforce Developers
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong Foundations
Salesforce Developers12.8K views
Building a Serverless company with Node.js, React and the Serverless Framewor... by Luciano Mammino
Building a Serverless company with Node.js, React and the Serverless Framewor...Building a Serverless company with Node.js, React and the Serverless Framewor...
Building a Serverless company with Node.js, React and the Serverless Framewor...
Luciano Mammino2.9K views
Getting start Java EE Action-Based MVC with Thymeleaf by Masatoshi Tada
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with Thymeleaf
Masatoshi Tada4.2K views
Aop spring by chamilavt
Aop springAop spring
Aop spring
chamilavt710 views
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th... by MongoDB
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB339 views
Raising the Bar on Robotics Code Quality by Thomas Moulard
Raising the Bar on Robotics Code QualityRaising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code Quality
Thomas Moulard1.2K views
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless by KatyShimizu
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu845 views
[NDC 2019] Enterprise-Grade Serverless by KatyShimizu
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu118 views
Re-checking the ReactOS project - a large report by PVS-Studio
Re-checking the ReactOS project - a large reportRe-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large report
PVS-Studio397 views
The Art of The Event Streaming Application: Streams, Stream Processors and Sc... by confluent
The Art of The Event Streaming Application: Streams, Stream Processors and Sc...The Art of The Event Streaming Application: Streams, Stream Processors and Sc...
The Art of The Event Streaming Application: Streams, Stream Processors and Sc...
confluent923 views
Kakfa summit london 2019 - the art of the event-streaming app by Neil Avery
Kakfa summit london 2019 - the art of the event-streaming appKakfa summit london 2019 - the art of the event-streaming app
Kakfa summit london 2019 - the art of the event-streaming app
Neil Avery595 views
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC... by Andrey Karpov
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
Andrey Karpov27 views

More from Dror Helper

Unit testing patterns for concurrent code by
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent codeDror Helper
429 views44 slides
The secret unit testing tools no one ever told you about by
The secret unit testing tools no one ever told you aboutThe secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you aboutDror Helper
273 views40 slides
Debugging with visual studio beyond 'F5' by
Debugging with visual studio beyond 'F5'Debugging with visual studio beyond 'F5'
Debugging with visual studio beyond 'F5'Dror Helper
306 views29 slides
From clever code to better code by
From clever code to better codeFrom clever code to better code
From clever code to better codeDror Helper
198 views38 slides
From clever code to better code by
From clever code to better codeFrom clever code to better code
From clever code to better codeDror Helper
236 views26 slides
A software developer guide to working with aws by
A software developer guide to working with awsA software developer guide to working with aws
A software developer guide to working with awsDror Helper
1.3K views23 slides

More from Dror Helper(20)

Unit testing patterns for concurrent code by Dror Helper
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
Dror Helper429 views
The secret unit testing tools no one ever told you about by Dror Helper
The secret unit testing tools no one ever told you aboutThe secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you about
Dror Helper273 views
Debugging with visual studio beyond 'F5' by Dror Helper
Debugging with visual studio beyond 'F5'Debugging with visual studio beyond 'F5'
Debugging with visual studio beyond 'F5'
Dror Helper306 views
From clever code to better code by Dror Helper
From clever code to better codeFrom clever code to better code
From clever code to better code
Dror Helper198 views
From clever code to better code by Dror Helper
From clever code to better codeFrom clever code to better code
From clever code to better code
Dror Helper236 views
A software developer guide to working with aws by Dror Helper
A software developer guide to working with awsA software developer guide to working with aws
A software developer guide to working with aws
Dror Helper1.3K views
The secret unit testing tools no one has ever told you about by Dror Helper
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you about
Dror Helper340 views
The role of the architect in agile by Dror Helper
The role of the architect in agileThe role of the architect in agile
The role of the architect in agile
Dror Helper269 views
Harnessing the power of aws using dot net core by Dror Helper
Harnessing the power of aws using dot net coreHarnessing the power of aws using dot net core
Harnessing the power of aws using dot net core
Dror Helper281 views
Developing multi-platform microservices using .NET core by Dror Helper
 Developing multi-platform microservices using .NET core Developing multi-platform microservices using .NET core
Developing multi-platform microservices using .NET core
Dror Helper408 views
Harnessing the power of aws using dot net by Dror Helper
Harnessing the power of aws using dot netHarnessing the power of aws using dot net
Harnessing the power of aws using dot net
Dror Helper217 views
Secret unit testing tools no one ever told you about by Dror Helper
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you about
Dror Helper458 views
C++ Unit testing - the good, the bad & the ugly by Dror Helper
C++ Unit testing - the good, the bad & the uglyC++ Unit testing - the good, the bad & the ugly
C++ Unit testing - the good, the bad & the ugly
Dror Helper1.9K views
Working with c++ legacy code by Dror Helper
Working with c++ legacy codeWorking with c++ legacy code
Working with c++ legacy code
Dror Helper749 views
Visual Studio tricks every dot net developer should know by Dror Helper
Visual Studio tricks every dot net developer should knowVisual Studio tricks every dot net developer should know
Visual Studio tricks every dot net developer should know
Dror Helper525 views
Secret unit testing tools by Dror Helper
Secret unit testing toolsSecret unit testing tools
Secret unit testing tools
Dror Helper460 views
Electronics 101 for software developers by Dror Helper
Electronics 101 for software developersElectronics 101 for software developers
Electronics 101 for software developers
Dror Helper1.2K views
Navigating the xDD Alphabet Soup by Dror Helper
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
Dror Helper968 views
Building unit tests correctly by Dror Helper
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
Dror Helper1.4K views
Who’s afraid of WinDbg by Dror Helper
Who’s afraid of WinDbgWho’s afraid of WinDbg
Who’s afraid of WinDbg
Dror Helper1.9K views

Recently uploaded

SAP Automation Using Bar Code and FIORI.pdf by
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdfVirendra Rai, PMP
19 views38 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
15 views13 slides
virtual reality.pptx by
virtual reality.pptxvirtual reality.pptx
virtual reality.pptxG036GaikwadSnehal
11 views15 slides
Report 2030 Digital Decade by
Report 2030 Digital DecadeReport 2030 Digital Decade
Report 2030 Digital DecadeMassimo Talia
14 views41 slides
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
21 views35 slides
STPI OctaNE CoE Brochure.pdf by
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
12 views1 slide

Recently uploaded(20)

SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta15 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec11 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
6g - REPORT.pdf by Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex9 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views

Introduction to aop

  • 1. Introduction to AOP Dror Helper @dhelper
  • 2. About.Me  Software developer and technical lead  PostSharp MVP  Blogger: http://blog.drorhelper.com
  • 3. Developer write code void transfer(Account fromAcc, Account toAcc, int amount) { if (fromAcc.getBalance() < amount) { throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 4. Permission support – Right away! void transfer(Account fromAcc, Account toAcc, int amount, User user) { if (! checkUserPermission(user)) { throw new UnauthorizedUserException(); } if (fromAcc.getBalance() < amount) { throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 5. Need to check parameters – Done! void transfer(Account fromAcc, Account toAcc, int amount, User user) { if(fromAcc == null || toAcc == null) { throw new IllegalArgumentException (); } if(balance <= 0) { throw new IllegalArgumentException (); } if (! checkUserPermission(user)) { throw new UnauthorizedUserException(); } if (fromAcc.getBalance() < amount) { throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 6. Needs logging – no problems! void transfer(Account fromAcc, Account toAcc, int amount, User user) { logger.info("transferring money..."); if(balance <= 0) { throw new IllegalArgumentException (); } if (! checkUserPermission(user)) { logger.info("User has no permission."); throw new UnauthorizedUserException(); } if (fromAcc.getBalance() < amount) { logger.info("Insufficient Funds, sorry"); throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount);
  • 7. And finally – exception handling void transfer(Account fromAcc, Account toAcc, int amount, User user) { logger.info("transferring money..."); if(balance <= 0) { throw new IllegalArgumentException (); } if (! checkUserPermission(user)) { logger.info("User has no permission."); throw new UnauthorizedUserException(); } if (fromAcc.getBalance() < amount) { logger.info("Insufficient Funds, sorry"); throw new InsufficientFundsException(); } try { fromAcc.withdraw(amount); toAcc.deposit(amount); } catch(Exception exc) { logger.info(“failed transaction."); return; }
  • 9. The Problem  Code duplication  Hard to read  Difficult to maintain  Not all programmers code the same Ctrl + C, Ctrl + V
  • 10. Problem - Cross cutting concerns Customer Product Order Logging Cross-Cutting Security Concerns Caching
  • 11. Non-Functional Requirements  Security  Caching  Tracing  Exception handling  Monitoring  Validation  Persistence  Transactions  Thread sync
  • 12. Solution  AOP  Separation of concerns  Extension of OOP 1. Encapsulate Cross cutting concerns into aspects 2. Apply aspects to code
  • 13. Why AOP • AOP exist for more then 15 Mature years Industry • Industry standard adopted Observed • -15% lines of code Benefits • -20% decoupling
  • 15. Join Point static void Main() { myClass1.Func1 var myClass1 = new MyClass(); var myClass2 = new MyClass(); myClass1.Func1(); myClass1.Func2(2, 3); myClass1.Func2 myClass2.Func2(4, 5); } myClass2.Func2
  • 16. Point Cuts myClass1.Func1 myClass1.Func2 Before Func2 myClass2.Func2
  • 17. Advice  The code to run  Typically small  Injected at join point
  • 18. Aspect Join Point + Advice = Aspect
  • 20. Our example for today – the calculator
  • 22. #1 Functional programming  Using higher order functions to “warp” existing code  Decorator pattern
  • 23. 1# Functional Programming + -  No additional  You cannot automatically dependency in your pass context from the caller to the aspect code build or runtime code.  Must modify the code of  Programmers are every method to which already familiar with the you want to add the technology. aspect.  Aspect composition is less convenient.
  • 24. Why not use existing tools
  • 25. What IoC containers can do for you?  Enable Dependency Injection (DI)  Create objects and satisfy it’s dependencies  A lot more..
  • 26. #2 Dynamic proxies Framework Application Proxy Aspect Object
  • 27. .NET IoC tools  Unity http://unity.codeplex.com/  Spring.NET http://www.springframework.net/  Castle http://www.castleproject.org/
  • 28. Dynamic proxies + -  You may already be  Very limited aspect-oriented features. using a DI framework.  Your objects must be instantiated using the  Aspects can be container configured after build.  Does not work on static, non-public, and/or  Some aspects may be non-virtual methods provided by the  Does not work on framework. fields, properties, or events.
  • 29. #3 MSIL transformations IL Final Code Compile weaving Assembly
  • 30. IL transformation tools  Mono.Cecil http://www.mono-project.com/Cecil  NotifyPropertyWeaver http://code.google.com/p/notifypropertyweaver/
  • 31. MSIL transformations + -  Very powerful. You can  Requires an advanced knowledge of MSIL. achieve virtually any code transformation  Very low level  These frameworks are  typically do not compose well when many are free of charge and applied to the same backed by large method. companies.  No Visual Studio tooling.
  • 32. #4 Build time AOP Build Process Intermediate Final Source Compiler Assembly AOP Assembly Code (IL) Aspects
  • 33. Summery Use AOP because:  Less code = fewer bugs  Less code = easier to read and maintain  Reduce duplicate code  Improve team work/architecture  Reduce development cost
  • 34. Resources Cross Cutting Concerns blog http://crosscuttingconcerns.com/ My blog: http://blog.drorhelper.com

Editor's Notes

  1. Non functional requirments
  2. A call to a methodThe method’s executionAssignment to a variableReturn statementObject constructionConditional checkComparisonException handlerLoops
  3. A group of Join pointFilter drivenAttribute driven
  4. IoC containers
  5. Using IoC containers
  6. Add IL in compile timeDifficult and fragile“Mini AOPs”
  7. Adding step to compilationUsing IL weavingShow diagram