SlideShare a Scribd company logo
Aspect-Oriented Programming
Coming up…What is AOP?Why do we need AOP?How does AOP work?Hello World2
What is AOP?Part of AOSDAn extension of OOP extracting cross-cutting functional units of systemsA means of programming such functional units separate from other code, which are then ‘woven’ togetherAn attempt at promoting good SE practices within OOP3
Why do we need AOP?Situation in a typical O-O system:A single requirement implemented by multiple components (tangling)A single component may include elements of multiple requirements (scattering)Change could require understanding and changing many componentsThis impacts on software reuse4
Tangling example – sharedbuffer5Tangled buffer management codeTangled synchronisation codeSource: Sommerville, I. (2007)
Scattering example – patient records6Source: Sommerville, I. (2007)The highlighted operations implement secondary concerns for the system, such as keeping patient and consultant details anonymousIf the policy regarding anonymity changed, we would need to recode each version of anonymise() throughout the system
The AOP approachThree key stages:Aspectual DecomopositionConcern ImplementationAspectual Recomposition7
How are concerns identified?8A prismSource: Laddad, R. (2003)
Concern TypesFunctionalQuality of ServicePolicySystemOrganisational9Functionalrelated to specific functionality to be included in the systemin a train control system, a specific functional concern is train brakingQuality of Servicerelated to the non-functional behaviour of a systemperformance, reliability, availabilityPolicyrelated to the overall policies that govern the use of the systemsecurity, safety, concerns related to business rulesSystemrelated to attributes of the system as a wholemaintainability, configurabilityOrganisationalrelated to organisational goals and prioritiesproducing a system within budget, making use of existing software assets, maintaining the reputation of an organisation
Concern ClassificationsCoreFunctional concerns that directly relate to the primary purpose of a system.SecondaryFunctionality that shares information with the core concernsFunctionality that satisfies NFRsCross-cuttingConcerns that apply to the system as a whole10
Cross-cutting example11New customerreq.Customer management req.Account managementreq.Securityreq.Cross-cuttingconcernsRecoveryreq.Core concernsSource: Sommerville, I. (2007)
Implementing ConcernsCoreClasses & OperationsCross-cutting / SecondaryAspectsAdvice; Join Points; Pointcuts12
AspectAspects are similar to classes in that they can:include data members and operationshave access specificationsdeclare themselves to be abstractextend classes and abstract aspects and implement interfacesbe embedded inside classes and interfaces as nested aspectsThey are dissimilar in that they cannot:be directly instantiatedinherit from concrete aspectsbe marked as privileged13
Join PointAny identifiable execution point in a systemA call to a methodThe method’s executionAssignment to a variableReturn statementObject constructionConditional checkComparisonException handlerLoopsNot all may be exposed by each AOP languageAspectJ does not expose loops14
PointcutPointcuts capture, or identify, one or more join points&&	||Need not be given a nameAnonymous pointcutsmust be specified as part of adviceCan include wildcards15
AdviceThe code to be executed at a join pointThe join point must have been selected by a pointcutCan be defined as:BeforeAfterAround16
O-O Hello World17> javacMessageCommunicator.java Test.java> java testWanna learn AspectJHarry, having fun?
A-O Hello World18pointcutadvice> ajc MessageCommunicator.java MannersAspect.java Test.java> java TestHello! Wanna learn AspectJ?Hello! Harry, having fun?
A-O Hello World 219> ajc MessageCommunicator.java MannersAspect.java Hindi Salutation.java Test.java> java TestHello! Wanna learn AspectJ?Hello! Harry-ji, having fun?
Another aspect example20
How do we get a working program?21Source: Laddad, R. (2003)
Benefits of AOPCleaner responsibilities of the individual moduleHigher modularisationEasier system evolutionLate binding of design decisionsMore code reuseImprove time-to-marketReduced costs of feature implementation22
Realities of AOPProgram flow is hard to followDoesn’t solve any new problemsBreaks encapsulation23
Terms to rememberAdvicethe code implementing a concernAspectprogram abstraction defining a cross-cutting concern. Includes a definition of one or more pointcutsand the advice associated with that concernJoin pointan event in a program where the advice associated with an aspect may be executedJoin point modelset of events referenced in a pointcutPointcutaspect statement defining join points where the associated aspect advice should be executedWeavingincorporation of advice code at specified join points by an aspect weaver24
Useful SourcesBooksLaddad, R. (2003), AspectJ in Action, Manning Publications Co.Sommerville, I. (2007), Software Engineering, 8th edition, Pearson Education Ltd.OnlineThe AspectJ Project - http://www.eclipse.org/aspectj/VideoGoogleTechTalks (2007), Aspect Oriented Programming: Radical Research in Modularity. Available at: http://www.youtube.com/watch?v=cq7wpLI0hco25

More Related Content

What's hot (20)

PDF
Model Based Systems and Software Engineering an overview of the IBM Rational ...
Real-Time Innovations (RTI)
 
PDF
Firstenberg q207
Obsidian Software
 
PPTX
Git branching policy and review comment's prefix
Kumaresh Chandra Baruri
 
PPTX
Unit Testing in Action - C#, NUnit, and Moq
XPDays
 
PPTX
09 coding standards_n_guidelines
University of Computer Science and Technology
 
PPTX
Inversion of control
Emmet Irish
 
PDF
Bristol 2009 q1_eder_kersten
Obsidian Software
 
PPTX
From catalogues to models: transitioning from existing requirements technique...
James Towers
 
PDF
Bangalore march07
Obsidian Software
 
PDF
Formal Verification
Ilia Levin
 
PPTX
Clean coding in plsql and sql
Brendan Furey
 
PDF
Laws of test automation framework
vodqancr
 
PPT
Code review
dqpi
 
ODP
FluentSelenium Presentation Code Camp09
Pyxis Technologies
 
PDF
Formal verification
DIlawar Singh
 
PPT
Introduction To Design Patterns
sukumarraju6
 
PPT
Software Coding- Software Coding
Nikhil Pandit
 
PDF
Throwing Laravel into your Legacy App™
Joe Ferguson
 
PPT
Software coding & testing, software engineering
Rupesh Vaishnav
 
Model Based Systems and Software Engineering an overview of the IBM Rational ...
Real-Time Innovations (RTI)
 
Firstenberg q207
Obsidian Software
 
Git branching policy and review comment's prefix
Kumaresh Chandra Baruri
 
Unit Testing in Action - C#, NUnit, and Moq
XPDays
 
09 coding standards_n_guidelines
University of Computer Science and Technology
 
Inversion of control
Emmet Irish
 
Bristol 2009 q1_eder_kersten
Obsidian Software
 
From catalogues to models: transitioning from existing requirements technique...
James Towers
 
Bangalore march07
Obsidian Software
 
Formal Verification
Ilia Levin
 
Clean coding in plsql and sql
Brendan Furey
 
Laws of test automation framework
vodqancr
 
Code review
dqpi
 
FluentSelenium Presentation Code Camp09
Pyxis Technologies
 
Formal verification
DIlawar Singh
 
Introduction To Design Patterns
sukumarraju6
 
Software Coding- Software Coding
Nikhil Pandit
 
Throwing Laravel into your Legacy App™
Joe Ferguson
 
Software coding & testing, software engineering
Rupesh Vaishnav
 

Viewers also liked (9)

PPT
Aspect Oriented Programming
Anumod Kumar
 
ODP
Aspect-Oriented Programming
Andrey Bratukhin
 
PPTX
Introduction to Aspect Oriented Programming
Yan Cui
 
PPTX
Aspect Oriented Programming
Rajesh Ganesan
 
PPTX
Introduction To Aspect Oriented Programming
saeed shargi ghazani
 
PPTX
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Yan Cui
 
PDF
AOP
Joshua Yoon
 
PDF
Aspect-Oriented Programming (AOP) in .NET
Yuriy Guts
 
PPTX
Produce Cleaner Code with Aspect-Oriented Programming
PostSharp Technologies
 
Aspect Oriented Programming
Anumod Kumar
 
Aspect-Oriented Programming
Andrey Bratukhin
 
Introduction to Aspect Oriented Programming
Yan Cui
 
Aspect Oriented Programming
Rajesh Ganesan
 
Introduction To Aspect Oriented Programming
saeed shargi ghazani
 
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Yan Cui
 
Aspect-Oriented Programming (AOP) in .NET
Yuriy Guts
 
Produce Cleaner Code with Aspect-Oriented Programming
PostSharp Technologies
 
Ad

Similar to Aspect Oriented Programming (20)

PPTX
Slcm sharbani bhattacharya
Sharbani Bhattacharya
 
PPT
Mba it unit 3 ppt
Suguna Ramya
 
PPT
Mba it unit 3 ppt
Suguna Ramya
 
PPT
Mba it unit 3 ppt
Suguna Ramya
 
DOCX
Ooad lab manual(original)
dipenpatelpatel
 
PDF
System Development Life Cycle ( Sdlc )
Jennifer Wright
 
PDF
software requirement and architecture.pdf
wajoce8790
 
PPT
3-Requirements.ppt
DuraisamySubramaniam1
 
PPTX
Software engineering concept reengineeri
SanaMateen7
 
PDF
6-180117160306. software engineering concepts
NMahendiran
 
PPT
ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
Swarnima Tiwari
 
PDF
6. ch 5-understanding requirements
Delowar hossain
 
PPT
Software engg. pressman_ch-6 & 7
Dhairya Joshi
 
PDF
chapter no 2softwareprocess-160107000546.f
DuaRajpoot2
 
PDF
Software Engineering Important Short Question for Exams
MuhammadTalha436
 
PPTX
Sdpl1
sraviinthiran
 
PPTX
Ch 2-RE-process.pptx
balewayalew
 
PPTX
Aspect Oriented Programming - AOP/AOSD
Can R. PAHALI
 
PPT
2. Sofware process and models FOR THE UNIT
sharmila27432
 
PDF
Se lec-uosl-8
Shahzad Zaman
 
Slcm sharbani bhattacharya
Sharbani Bhattacharya
 
Mba it unit 3 ppt
Suguna Ramya
 
Mba it unit 3 ppt
Suguna Ramya
 
Mba it unit 3 ppt
Suguna Ramya
 
Ooad lab manual(original)
dipenpatelpatel
 
System Development Life Cycle ( Sdlc )
Jennifer Wright
 
software requirement and architecture.pdf
wajoce8790
 
3-Requirements.ppt
DuraisamySubramaniam1
 
Software engineering concept reengineeri
SanaMateen7
 
6-180117160306. software engineering concepts
NMahendiran
 
ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
Swarnima Tiwari
 
6. ch 5-understanding requirements
Delowar hossain
 
Software engg. pressman_ch-6 & 7
Dhairya Joshi
 
chapter no 2softwareprocess-160107000546.f
DuaRajpoot2
 
Software Engineering Important Short Question for Exams
MuhammadTalha436
 
Ch 2-RE-process.pptx
balewayalew
 
Aspect Oriented Programming - AOP/AOSD
Can R. PAHALI
 
2. Sofware process and models FOR THE UNIT
sharmila27432
 
Se lec-uosl-8
Shahzad Zaman
 
Ad

Aspect Oriented Programming

  • 2. Coming up…What is AOP?Why do we need AOP?How does AOP work?Hello World2
  • 3. What is AOP?Part of AOSDAn extension of OOP extracting cross-cutting functional units of systemsA means of programming such functional units separate from other code, which are then ‘woven’ togetherAn attempt at promoting good SE practices within OOP3
  • 4. Why do we need AOP?Situation in a typical O-O system:A single requirement implemented by multiple components (tangling)A single component may include elements of multiple requirements (scattering)Change could require understanding and changing many componentsThis impacts on software reuse4
  • 5. Tangling example – sharedbuffer5Tangled buffer management codeTangled synchronisation codeSource: Sommerville, I. (2007)
  • 6. Scattering example – patient records6Source: Sommerville, I. (2007)The highlighted operations implement secondary concerns for the system, such as keeping patient and consultant details anonymousIf the policy regarding anonymity changed, we would need to recode each version of anonymise() throughout the system
  • 7. The AOP approachThree key stages:Aspectual DecomopositionConcern ImplementationAspectual Recomposition7
  • 8. How are concerns identified?8A prismSource: Laddad, R. (2003)
  • 9. Concern TypesFunctionalQuality of ServicePolicySystemOrganisational9Functionalrelated to specific functionality to be included in the systemin a train control system, a specific functional concern is train brakingQuality of Servicerelated to the non-functional behaviour of a systemperformance, reliability, availabilityPolicyrelated to the overall policies that govern the use of the systemsecurity, safety, concerns related to business rulesSystemrelated to attributes of the system as a wholemaintainability, configurabilityOrganisationalrelated to organisational goals and prioritiesproducing a system within budget, making use of existing software assets, maintaining the reputation of an organisation
  • 10. Concern ClassificationsCoreFunctional concerns that directly relate to the primary purpose of a system.SecondaryFunctionality that shares information with the core concernsFunctionality that satisfies NFRsCross-cuttingConcerns that apply to the system as a whole10
  • 11. Cross-cutting example11New customerreq.Customer management req.Account managementreq.Securityreq.Cross-cuttingconcernsRecoveryreq.Core concernsSource: Sommerville, I. (2007)
  • 12. Implementing ConcernsCoreClasses & OperationsCross-cutting / SecondaryAspectsAdvice; Join Points; Pointcuts12
  • 13. AspectAspects are similar to classes in that they can:include data members and operationshave access specificationsdeclare themselves to be abstractextend classes and abstract aspects and implement interfacesbe embedded inside classes and interfaces as nested aspectsThey are dissimilar in that they cannot:be directly instantiatedinherit from concrete aspectsbe marked as privileged13
  • 14. Join PointAny identifiable execution point in a systemA call to a methodThe method’s executionAssignment to a variableReturn statementObject constructionConditional checkComparisonException handlerLoopsNot all may be exposed by each AOP languageAspectJ does not expose loops14
  • 15. PointcutPointcuts capture, or identify, one or more join points&& ||Need not be given a nameAnonymous pointcutsmust be specified as part of adviceCan include wildcards15
  • 16. AdviceThe code to be executed at a join pointThe join point must have been selected by a pointcutCan be defined as:BeforeAfterAround16
  • 17. O-O Hello World17> javacMessageCommunicator.java Test.java> java testWanna learn AspectJHarry, having fun?
  • 18. A-O Hello World18pointcutadvice> ajc MessageCommunicator.java MannersAspect.java Test.java> java TestHello! Wanna learn AspectJ?Hello! Harry, having fun?
  • 19. A-O Hello World 219> ajc MessageCommunicator.java MannersAspect.java Hindi Salutation.java Test.java> java TestHello! Wanna learn AspectJ?Hello! Harry-ji, having fun?
  • 21. How do we get a working program?21Source: Laddad, R. (2003)
  • 22. Benefits of AOPCleaner responsibilities of the individual moduleHigher modularisationEasier system evolutionLate binding of design decisionsMore code reuseImprove time-to-marketReduced costs of feature implementation22
  • 23. Realities of AOPProgram flow is hard to followDoesn’t solve any new problemsBreaks encapsulation23
  • 24. Terms to rememberAdvicethe code implementing a concernAspectprogram abstraction defining a cross-cutting concern. Includes a definition of one or more pointcutsand the advice associated with that concernJoin pointan event in a program where the advice associated with an aspect may be executedJoin point modelset of events referenced in a pointcutPointcutaspect statement defining join points where the associated aspect advice should be executedWeavingincorporation of advice code at specified join points by an aspect weaver24
  • 25. Useful SourcesBooksLaddad, R. (2003), AspectJ in Action, Manning Publications Co.Sommerville, I. (2007), Software Engineering, 8th edition, Pearson Education Ltd.OnlineThe AspectJ Project - http://www.eclipse.org/aspectj/VideoGoogleTechTalks (2007), Aspect Oriented Programming: Radical Research in Modularity. Available at: http://www.youtube.com/watch?v=cq7wpLI0hco25

Editor's Notes

  • #4: AOSD – Aspect Oriented Software DevelopmentSE – Software EngineeringOOP – Object-Oriented Programming
  • #6: Shared bufferAccessed by a number of components such as this oneLook at the first conditionalLook at notify()
  • #7: Introduce the classesBring attention to the lower operations – note common operation – anonymise()Good indication of scattering is common operation names
  • #8: Aspectual Decomposition – identification of individual concerns from reqsConcern Implementation – codingAspectual Recomposition – weaving of code into working system
  • #9: An analogy – a prism can be used to separate light into constituent coloursAspectual Decomposition is the identification of individual concerns from the system’s requirementsSo, if we call our prism a ‘Concern Identifier’ and, instead of light, we pass through the system’s requirements…We can see that it is possible to identify individual concernsNote that the concern identifier is specific to a particular system, depending heavily on the focus of the business
  • #10: Functional – related to specific functionality to be included in the systemExample– in a train control system, a specific functional concern is train brakingQuality of Service – related to the non-functional behaviour of a systemExamples– performance, reliability, availabilityPolicy – related to the overall policies that govern the use of the systemExamples– security, safety, concerns related to business rulesSystem – related to attributes of the system as a wholeExamples – maintainability, configurabilityOrganisational – related to organisational goals and prioritiesExamples – producing a system within budget, making use of existing software assets, maintaining the reputation of an organisation
  • #12: Lets take the example of an Internet banking systemThe system will have requirements relating to:New customers, such as credit checking / address verificationIt will also have reqs relating to the management of existing customers… As well as those relating to customer accountsAll of these will generate CORE concerns as they associate with the system’s primary focus – the provision of an Internet banking serviceHowever, the system also has security requirements based on the bank’s security policy…And recovery requirements to ensure that data is not lost in the event of a system failure…These generate cross-cutting concerns as they may influence the implementation of all the other system requirements
  • #19: Lets say we want to add ‘Hello! ‘ to the beginning of the response.We could just amend MessageCommunicator to this effect, but imagine having to sift through multiple files trying to find all the relevant execution codeA much simpler means of doing this is to use an aspect. We can accomplish this be defining a pointcut that registers any call to deliver, and also advice to be applied before the execution of deliver.Note the asterisk in the pointcutThis means that this pointcut will capture ANY call to MessageCommunicator.deliver regardless of access specifierEg Public / Private / Static / Return typeNote the use of ajc instead of javac – this is the AspectJ compilation command
  • #20: Now, say we want to include a language-appropriate salutation.In Hindi, the suffix ‘ji’ is often added to a person’s name to show respect, much like appending ‘san’ in Japanese. We can make this modification by defining another aspect that will pickup on the call to deliverNote the binary operator defining a second argument to the pointcut…This allows for the assignment of person, corresponding to the first argument.Note the use of String here. The second argument is not given a defining name as it is not required within this scope
  • #21: So lets take another example…Here we have an aspect called authentication that contains one piece of adviceNote that this advice will occur before the identified operation is executedNote also that, in this example, we have an anonymous piece of advice
  • #22: So how do we get a working program from these distinct concerns?This is where we use Aspectual Recomposition to combine themThis is accomplished by WEAVING the code into the final working systemThe WEAVER is a special type of compiler that is capable of this functionality
  • #23: So what are the reported benefits of AOP?AOP allows a module to take responsibility only for its core concern; a module is no longer liable for other cross-cutting concernsAOP provides a mechanism to address each concern separately with minimal coupling; resulting in a system with much less duplicated codeAOP modularises individual aspects and makes core modules oblivious to the aspects; adding new functionality is now a matter of including a new aspect and requires no change to the core modulesThe developer can delay making design decisions for future requirements because it is possible to implement those as separate aspectsCore modules aren’t aware of each other, only aspects are aware of any coupling in the implementationLate binding of design decisions allows for a much faster design cycleBy avoiding the cost of modifying many modules to implement a cross-cutting concern
  • #24: The programmer needs to be aware of any join points that relate to a particular piece of codeAOP is not attempting to provide solutions to unsolved programming problems, merely attempting to provide a means of going about those solved problems with less effort and improved maintainabilityIn OOP, a class encapsulates all the behaviour of an object. Aspects remove this level of control from the class