SlideShare a Scribd company logo
1 of 48
Aspect-Oriented Programming: The Good, the Bad, the Ugly and the Hope John Lam Naleco Research Inc. http://www.iunknown.com
John Lam ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object]
The view from 35,000 feet
Monolithic programs
Modular programming
Object-oriented programming
AOP: Identifying cross-cuts
AOP: Defining aspects
AOP: Weaving aspects
The view from 5,000 feet
Monolithic programs
What is software? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Tackling the software problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Unstructured code ,[object Object],[object Object],10 let i = 1 20 if i > 4 then goto 60 30 print i 40 i = i + 1 50 goto 20 60 print "done"
Elegant unstructured code ,[object Object],[object Object],[object Object],[object Object],10 let i = 1 20 print i 30 i = i + 1 40 if i < 4 then goto 20 50 print &quot;done&quot;
Language support for elegance ,[object Object],[object Object],int i = 1; while( i < 4 ) { print( i ); }
Why does elegance matter? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Is elegance enough? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Modular programming
Modularization ,[object Object],[object Object],[object Object]
Modularization: Windows ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Modularization and Abstraction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Is modularization enough? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Object-oriented programming
Object-oriented programming ,[object Object],[object Object],[object Object],[object Object],[object Object]
OOP: .NET Frameworks System.Object System.Web.UI.Control WebControl Button Repeater CheckBox HyperLink Image AdRotator Calendar ValidationSummary System.Web.UI.WebControls Namespace Label LinkButton Panel RadioButton ImageButton Table BaseDataList DataList DataGrid ListControl CheckBoxList DropDownList ListBox RadioButtonList BaseValidator CompareValidator CustomValidator RangeValidator RegularExpressionValidator RequiredFieldValidator TableCell TableRow TextBox TableHeaderCell
Is OOP enough? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
AOP: Identifying cross-cuts
AOP: Defining aspects
AOP: Weaving aspects
Aspect-Oriented Programming ,[object Object],[object Object],[object Object]
The view from 50 feet
The Good: AOP solves problems Public Function ReadEmployeeSalary( id as Integer ) as Single Trace.WriteLine( String.Format( &quot;Reading employee # {0}'s salary&quot;, id ) ) If System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ) Then Try ' Code that reads employee's salary Catch e as FatalException Logging.LogFatalException( e, &quot;ReadEmployeeSalary&quot; ) End Try End If End Sub
Policies and software ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Aspects can implement policies Public Function ReadEmployeeSalary( id as Integer ) as Single Trace.WriteLine( String.Format( &quot;Reading employee # {0}'s salary&quot;, id ) ) If System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ) Then Try ' Code that reads employee's salary Catch e as FatalException Logging.LogFatalException( e, &quot;ReadEmployeeSalary&quot; ) End Try End If End Sub 1 2 3
Aspects can implement policies public class SecurityPolicy { public bool AccessCheck() { return System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ); } } public class TracingPolicy { public void Before( CallContext c ) { Trace.WriteLine( String.Format( &quot;Called: {0}&quot;, c.MethodName ) ); } } public class ExceptionPolicy { public void Thrown( FatalException e ) { Logger.LogFatalException( e ); } } 1 2 3
Weaving aspects before methods public class TracingPolicy { public void Before( CallContext c ) { Trace.WriteLine( String.Format( &quot;Called: {0}&quot;, c.MethodName ) ); } } <weave> <aspect target=&quot;public *.*::*( * )&quot; type=&quot;Before&quot;  method=&quot;TracingPolicy.Before( CallContext )&quot;/> </weave>
Weaving aspects around methods public class SecurityPolicy { public bool AccessCheck() { return System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ); } } <weave> <aspect target=&quot; [ interface:ManagerOnly == true ]  public *.*::*( * )&quot; type=&quot;Around&quot;  method=&quot;SecurityPolicy.AccessCheck()&quot;/> </weave> [ ManagerOnly ] public interface ISensitiveEmployeeData { float ReadEmployeeSalary( int id ); ... }
Weaving aspects around methods public class ExceptionPolicy { public void Thrown( FatalException e ) { Logger.LogFatalException( e ); } } <weave> <aspect target=&quot;public *.*::*( * )&quot; type=&quot;Thrown( FatalException )&quot;  method=&quot;ExceptionPolicy.Thrown( FatalException )&quot;/> </weave>
The Bad: Stateful aspects ,[object Object],[object Object],[object Object],[object Object]
The Ugly: Aspect side-effects ,[object Object],[object Object],[object Object],[object Object]
One Hope ,[object Object]
Another Hope: Knowledge capture ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why should  you  use aspects? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Who can use aspects? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Types of aspect weavers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Where to go for more information ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Xml web services
Xml web servicesXml web services
Xml web services
Raghu nath
 

What's hot (20)

web service technologies
web service technologiesweb service technologies
web service technologies
 
Web API with ASP.NET MVC by Software development company in india
Web API with ASP.NET  MVC  by Software development company in indiaWeb API with ASP.NET  MVC  by Software development company in india
Web API with ASP.NET MVC by Software development company in india
 
Web service Introduction
Web service IntroductionWeb service Introduction
Web service Introduction
 
Web Service Presentation
Web Service PresentationWeb Service Presentation
Web Service Presentation
 
SOAP, UDDI, WSDL. XML definitions
SOAP, UDDI, WSDL. XML definitions SOAP, UDDI, WSDL. XML definitions
SOAP, UDDI, WSDL. XML definitions
 
Xml web services
Xml web servicesXml web services
Xml web services
 
CSS Architecture: Writing Maintainable CSS
CSS Architecture: Writing Maintainable CSSCSS Architecture: Writing Maintainable CSS
CSS Architecture: Writing Maintainable CSS
 
Web service assignment
Web service assignmentWeb service assignment
Web service assignment
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMING
 
Overview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB APIOverview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB API
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Web Services
Web ServicesWeb Services
Web Services
 
Web services
Web servicesWeb services
Web services
 
Introduction to webservices
Introduction to webservicesIntroduction to webservices
Introduction to webservices
 
Introduction to Web Services
Introduction to Web ServicesIntroduction to Web Services
Introduction to Web Services
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architecture
 
Web Engineering UNIT III as per RGPV Syllabus
Web Engineering UNIT III as per RGPV SyllabusWeb Engineering UNIT III as per RGPV Syllabus
Web Engineering UNIT III as per RGPV Syllabus
 
Web services
Web servicesWeb services
Web services
 
Web engineering notes unit 3
Web engineering notes unit 3Web engineering notes unit 3
Web engineering notes unit 3
 
Web service introduction
Web service introductionWeb service introduction
Web service introduction
 

Similar to Intro To AOP

Similar to Intro To AOP (20)

Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp Philly
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Throwing Laravel into your Legacy App™
Throwing Laravel into your Legacy App™Throwing Laravel into your Legacy App™
Throwing Laravel into your Legacy App™
 
CLR_via_CSharp_(Jeffrey_Richter_4th_Edition).pdf
CLR_via_CSharp_(Jeffrey_Richter_4th_Edition).pdfCLR_via_CSharp_(Jeffrey_Richter_4th_Edition).pdf
CLR_via_CSharp_(Jeffrey_Richter_4th_Edition).pdf
 
The seven pillars of aspnet
The seven pillars of aspnetThe seven pillars of aspnet
The seven pillars of aspnet
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
 
Intro1
Intro1Intro1
Intro1
 
The Seven Pillars Of Asp.Net
The Seven Pillars Of Asp.NetThe Seven Pillars Of Asp.Net
The Seven Pillars Of Asp.Net
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
Structured Software Design
Structured Software DesignStructured Software Design
Structured Software Design
 
The Design, Evolution and Use of KernelF
The Design, Evolution and Use of KernelFThe Design, Evolution and Use of KernelF
The Design, Evolution and Use of KernelF
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
One Engine Two Tools
One Engine Two ToolsOne Engine Two Tools
One Engine Two Tools
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs Public
 
So You Just Inherited a $Legacy Application...
So You Just Inherited a $Legacy Application...So You Just Inherited a $Legacy Application...
So You Just Inherited a $Legacy Application...
 

More from elliando dias

Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Recently uploaded

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Recently uploaded (20)

Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 

Intro To AOP

  • 1. Aspect-Oriented Programming: The Good, the Bad, the Ugly and the Hope John Lam Naleco Research Inc. http://www.iunknown.com
  • 2.
  • 3.
  • 4. The view from 35,000 feet
  • 11. The view from 5,000 feet
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 21.
  • 22.
  • 23.
  • 24.
  • 26.
  • 27. OOP: .NET Frameworks System.Object System.Web.UI.Control WebControl Button Repeater CheckBox HyperLink Image AdRotator Calendar ValidationSummary System.Web.UI.WebControls Namespace Label LinkButton Panel RadioButton ImageButton Table BaseDataList DataList DataGrid ListControl CheckBoxList DropDownList ListBox RadioButtonList BaseValidator CompareValidator CustomValidator RangeValidator RegularExpressionValidator RequiredFieldValidator TableCell TableRow TextBox TableHeaderCell
  • 28.
  • 32.
  • 33. The view from 50 feet
  • 34. The Good: AOP solves problems Public Function ReadEmployeeSalary( id as Integer ) as Single Trace.WriteLine( String.Format( &quot;Reading employee # {0}'s salary&quot;, id ) ) If System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ) Then Try ' Code that reads employee's salary Catch e as FatalException Logging.LogFatalException( e, &quot;ReadEmployeeSalary&quot; ) End Try End If End Sub
  • 35.
  • 36. Aspects can implement policies Public Function ReadEmployeeSalary( id as Integer ) as Single Trace.WriteLine( String.Format( &quot;Reading employee # {0}'s salary&quot;, id ) ) If System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ) Then Try ' Code that reads employee's salary Catch e as FatalException Logging.LogFatalException( e, &quot;ReadEmployeeSalary&quot; ) End Try End If End Sub 1 2 3
  • 37. Aspects can implement policies public class SecurityPolicy { public bool AccessCheck() { return System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ); } } public class TracingPolicy { public void Before( CallContext c ) { Trace.WriteLine( String.Format( &quot;Called: {0}&quot;, c.MethodName ) ); } } public class ExceptionPolicy { public void Thrown( FatalException e ) { Logger.LogFatalException( e ); } } 1 2 3
  • 38. Weaving aspects before methods public class TracingPolicy { public void Before( CallContext c ) { Trace.WriteLine( String.Format( &quot;Called: {0}&quot;, c.MethodName ) ); } } <weave> <aspect target=&quot;public *.*::*( * )&quot; type=&quot;Before&quot; method=&quot;TracingPolicy.Before( CallContext )&quot;/> </weave>
  • 39. Weaving aspects around methods public class SecurityPolicy { public bool AccessCheck() { return System.Threading.Thread.CurrentPrincipal.IsInRole( &quot;manager&quot; ); } } <weave> <aspect target=&quot; [ interface:ManagerOnly == true ] public *.*::*( * )&quot; type=&quot;Around&quot; method=&quot;SecurityPolicy.AccessCheck()&quot;/> </weave> [ ManagerOnly ] public interface ISensitiveEmployeeData { float ReadEmployeeSalary( int id ); ... }
  • 40. Weaving aspects around methods public class ExceptionPolicy { public void Thrown( FatalException e ) { Logger.LogFatalException( e ); } } <weave> <aspect target=&quot;public *.*::*( * )&quot; type=&quot;Thrown( FatalException )&quot; method=&quot;ExceptionPolicy.Thrown( FatalException )&quot;/> </weave>
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.