SlideShare a Scribd company logo
1 of 29
Introduction to Aspect-Oriented-Programming
TOPICS

 -   What is bad and good design ?
 -   Problem statement.
 -   What is AOP ?
 -   Demo
WHAT IS BAD DESIGN ?
WHAT IS BAD DESIGN ?

-the system is rigid: it's hard to change a part of the system
without affecting too many other parts of the system

-the system is fragile: when making a change, unexpected
parts of the system break

- the system or component is immobile: it is hard to reuse it in
another application because it cannot be disentangled from
the current application
class GarbageService
{
     public void Transfer(int sourceID, int destinationID, int size)
     {
         Storage source = Storage.GetById(sourceID);
         Storage destination = Storage.GetById(destinationID);

        var garbage = source.GetGarbage(size);
        destination.PutGarbage(garbage);
    }
}
class GarbageService
{
     public void Transfer(int sourceID, int destinationID, int size)
     {
            Trace.TraceInformation("Entering GarbageService.Transfer(
                sourceID={0},destinationID={1})", sourceID, destinationID);

           try
           {
                 Storage source = Storage.GetById(sourceID);
                 Storage destination = Storage.GetById(destinationID);

                 var garbage = source.GetGarbage(size);
                 destination.PutGarbage(garbage);
           }
           catch (Exception ex)
           {
               Trace.TraceError("Exception: GarbageService.Transfer(
               sourceID = {0}, destinationID = {1}) failed : {2}“,
                                sourceID, destinationID, ex.Message);
               throw;
           }
    }
}
class GarbageService
{
        public void Transfer(int sourceID, int destinationID, int size)
        {
            Trace.TraceInformation("Entering GarbageService.Transfer(sourceID = {0}, destinationID =
                                     {1})", sourceID, destinationID);

           if (sourceID <= 0)
           {
               throw new ArgumentOutOfRangeException("sourceID");
           }
           if (destinationID <= 0)
           {
               throw new ArgumentOutOfRangeException("destinationID");
           }
           if (size <= 0)
           {
               throw new ArgumentOutOfRangeException("size");
           }

           try
           {
                 Storage source = Storage.GetById(sourceID);
                 Storage destination = Storage.GetById(destinationID);

                 var garbage = source.GetGarbage(size);
                 destination.PutGarbage(garbage);
           }
           catch (Exception ex)
           {
               Trace.TraceError("Exception: GarbageService.Transfer(sourceID = {0}, destinationID = {1})
                                 failed : {2}“, sourceID, destinationID, ex.Message);
               throw;
           }
       }
}
REQUIREMENTS
• Functional Requirements
    • Line-of-business




• Non functional requirements
    • Logging
    • Caching
    • Transaction
    • Validation
    • Exception Handling
    • Thread Sync
    • GUI Binding
    • … and a lot more!
WHAT IS AOP ?
AOP - is a programming paradigm which aims to increase modularity by allowing the
       separation of cross-cutting concerns.


AOP - an approach that extends OOP and addresses the issue of cross-cutting
      concerns:
        • Encapsulate cross-cutting concerns into Aspects.
        • Improves code reusability, modularity and separation of concerns.
        • Reduces defects by reducing boiler – plate code.


With AOP, you still define the common functionality in one
place, but you can declaratively define how and where this
functionality is applied without having
to modify the class to which you are applying the new
feature.
AOP
• doesn’t solve any new problem
• it’s just another tool in your toolbox
• the main goal is nice separation of concerns
• a decrease in development costs and software
delivery time;
• an increase in application maintainability.
• reduce noise in source == more clean model
AOP TERMINOLOGY
• Join Point
   • place where behavior can be added
• Advice
   • code that can be injected at join points
• Point Cut
   • join points where advices should be applied
AOP WEAVING
• Compile time weaving
   • Source-Level Weaving
   • Modifying the MSIL code

• Run-Time weaving
   • Dynamic Proxy
PostSharp                               is the most

                comprehensive aspect-oriented framework for .NET



Gael Fraiteur
Demo
Philip Laureano
   Comparing Aspect Frameworks
      STATIC VS DYNAMIC AOP
                                       Spring.NET
PostSharp                 LinFu        Castle
                                       MS Unity/PIAB




Build-Time:               Hybrid       Run-Time:
Very Expressive                        Less Expressive
Robust Model                           Brittle Model
Not Invasive                           Invasive
Static                                 Dynamic
   Comparing Aspect Frameworks
EXPRESSIVENESS
What can you do with the framework?

                                          Spring.NET
                      PostSharp   Linfu                Unity/PIAB
                                            Castle
Method Interception      Yes      Yes        Yes          Yes
Private/Sealed
                         Yes      Yes
Member Interception
Event Interception       Yes
Member Introduction      Yes
We need Aspects!
We have
great frameworks!

More Related Content

What's hot

Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
elliando dias
 

What's hot (20)

Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
 
Corba model ppt
Corba model pptCorba model ppt
Corba model ppt
 
Common Object Request Broker Architecture
Common Object Request Broker ArchitectureCommon Object Request Broker Architecture
Common Object Request Broker Architecture
 
Intel open mp
Intel open mpIntel open mp
Intel open mp
 
Chapter 17 corba
Chapter 17 corbaChapter 17 corba
Chapter 17 corba
 
Api and Fluency
Api and FluencyApi and Fluency
Api and Fluency
 
Lecture4 corba
Lecture4   corbaLecture4   corba
Lecture4 corba
 
Corba
CorbaCorba
Corba
 
Sc11 presentation 2001_06_28
Sc11 presentation 2001_06_28Sc11 presentation 2001_06_28
Sc11 presentation 2001_06_28
 
Adapter 2pp
Adapter 2ppAdapter 2pp
Adapter 2pp
 
50+ java interview questions
50+ java interview questions50+ java interview questions
50+ java interview questions
 
Corba in power system
Corba in power systemCorba in power system
Corba in power system
 
CORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBACORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBA
 
CORBA - Introduction and Details
CORBA - Introduction and DetailsCORBA - Introduction and Details
CORBA - Introduction and Details
 
Apache Harmony: An Open Innovation
Apache Harmony: An Open InnovationApache Harmony: An Open Innovation
Apache Harmony: An Open Innovation
 
Unit iv
Unit ivUnit iv
Unit iv
 
Java interview-questions-and-answers
Java interview-questions-and-answersJava interview-questions-and-answers
Java interview-questions-and-answers
 
Corba
CorbaCorba
Corba
 
Corba concepts & corba architecture
Corba concepts & corba architectureCorba concepts & corba architecture
Corba concepts & corba architecture
 
Massively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerryMassively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerry
 

Similar to AOP in C# 2013

Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...
Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...
Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...
inovex GmbH
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Priyanka Aash
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
Edge AI and Vision Alliance
 

Similar to AOP in C# 2013 (20)

Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovJava 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
 
Slicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPISlicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPI
 
Scaling Big Data Mining Infrastructure Twitter Experience
Scaling Big Data Mining Infrastructure Twitter ExperienceScaling Big Data Mining Infrastructure Twitter Experience
Scaling Big Data Mining Infrastructure Twitter Experience
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
 
Swift Micro-services and AWS Technologies
Swift Micro-services and AWS TechnologiesSwift Micro-services and AWS Technologies
Swift Micro-services and AWS Technologies
 
Drilling Cyber Security Data With Apache Drill
Drilling Cyber Security Data With Apache DrillDrilling Cyber Security Data With Apache Drill
Drilling Cyber Security Data With Apache Drill
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using Scalding
 
Introduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processingIntroduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processing
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...
Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...
Bug bites Elephant? Test-driven Quality Assurance in Big Data Application Dev...
 
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCONMicroservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​
 
owasp lithuania chapter - exploit vs anti-exploit
owasp lithuania chapter - exploit vs anti-exploitowasp lithuania chapter - exploit vs anti-exploit
owasp lithuania chapter - exploit vs anti-exploit
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

AOP in C# 2013

  • 2.
  • 3. TOPICS - What is bad and good design ? - Problem statement. - What is AOP ? - Demo
  • 4. WHAT IS BAD DESIGN ?
  • 5. WHAT IS BAD DESIGN ? -the system is rigid: it's hard to change a part of the system without affecting too many other parts of the system -the system is fragile: when making a change, unexpected parts of the system break - the system or component is immobile: it is hard to reuse it in another application because it cannot be disentangled from the current application
  • 6.
  • 7.
  • 8.
  • 9. class GarbageService { public void Transfer(int sourceID, int destinationID, int size) { Storage source = Storage.GetById(sourceID); Storage destination = Storage.GetById(destinationID); var garbage = source.GetGarbage(size); destination.PutGarbage(garbage); } }
  • 10. class GarbageService { public void Transfer(int sourceID, int destinationID, int size) { Trace.TraceInformation("Entering GarbageService.Transfer( sourceID={0},destinationID={1})", sourceID, destinationID); try { Storage source = Storage.GetById(sourceID); Storage destination = Storage.GetById(destinationID); var garbage = source.GetGarbage(size); destination.PutGarbage(garbage); } catch (Exception ex) { Trace.TraceError("Exception: GarbageService.Transfer( sourceID = {0}, destinationID = {1}) failed : {2}“, sourceID, destinationID, ex.Message); throw; } } }
  • 11. class GarbageService { public void Transfer(int sourceID, int destinationID, int size) { Trace.TraceInformation("Entering GarbageService.Transfer(sourceID = {0}, destinationID = {1})", sourceID, destinationID); if (sourceID <= 0) { throw new ArgumentOutOfRangeException("sourceID"); } if (destinationID <= 0) { throw new ArgumentOutOfRangeException("destinationID"); } if (size <= 0) { throw new ArgumentOutOfRangeException("size"); } try { Storage source = Storage.GetById(sourceID); Storage destination = Storage.GetById(destinationID); var garbage = source.GetGarbage(size); destination.PutGarbage(garbage); } catch (Exception ex) { Trace.TraceError("Exception: GarbageService.Transfer(sourceID = {0}, destinationID = {1}) failed : {2}“, sourceID, destinationID, ex.Message); throw; } } }
  • 12. REQUIREMENTS • Functional Requirements • Line-of-business • Non functional requirements • Logging • Caching • Transaction • Validation • Exception Handling • Thread Sync • GUI Binding • … and a lot more!
  • 13. WHAT IS AOP ? AOP - is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns. AOP - an approach that extends OOP and addresses the issue of cross-cutting concerns: • Encapsulate cross-cutting concerns into Aspects. • Improves code reusability, modularity and separation of concerns. • Reduces defects by reducing boiler – plate code. With AOP, you still define the common functionality in one place, but you can declaratively define how and where this functionality is applied without having to modify the class to which you are applying the new feature.
  • 14. AOP • doesn’t solve any new problem • it’s just another tool in your toolbox • the main goal is nice separation of concerns • a decrease in development costs and software delivery time; • an increase in application maintainability. • reduce noise in source == more clean model
  • 15. AOP TERMINOLOGY • Join Point • place where behavior can be added • Advice • code that can be injected at join points • Point Cut • join points where advices should be applied
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. AOP WEAVING • Compile time weaving • Source-Level Weaving • Modifying the MSIL code • Run-Time weaving • Dynamic Proxy
  • 21. PostSharp is the most comprehensive aspect-oriented framework for .NET Gael Fraiteur
  • 22. Demo
  • 23.
  • 25. Comparing Aspect Frameworks STATIC VS DYNAMIC AOP Spring.NET PostSharp LinFu Castle MS Unity/PIAB Build-Time: Hybrid Run-Time: Very Expressive Less Expressive Robust Model Brittle Model Not Invasive Invasive Static Dynamic
  • 26. Comparing Aspect Frameworks EXPRESSIVENESS What can you do with the framework? Spring.NET PostSharp Linfu Unity/PIAB Castle Method Interception Yes Yes Yes Yes Private/Sealed Yes Yes Member Interception Event Interception Yes Member Introduction Yes
  • 27.