/
Aspect-Oriented Programming Aspect-Oriented Programming

Aspect-Oriented Programming - PowerPoint Presentation

phoebe-click
phoebe-click . @phoebe-click
Follow
400 views
Uploaded On 2017-06-24

Aspect-Oriented Programming - PPT Presentation

Coming up What is AOP Why do we need AOP How does AOP work Hello World 2 What is AOP Part of AOSD An extension of OOP extracting crosscutting functional units of systems A means of programming such functional units separate from other code which are then woven ID: 562793

system java join aop java system aop join concerns code aspect aspectj advice req source test 2007 cutting points pointcuts point concern

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Aspect-Oriented Programming" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Aspect-Oriented ProgrammingSlide2

Coming up…

What is AOP?

Why do we need AOP?

How does AOP work?Hello World

2Slide3

What is AOP?

Part of

AOSD

An extension of OOP extracting cross-cutting functional units of systemsA means of programming such functional units separate from other code, which are then ‘woven’

together

An

attempt at promoting good SE practices within OOP

3Slide4

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 components

This impacts on software reuse

4Slide5

Tangling example – shared

buffer

5

Tangled buffer management code

Tangled synchronisation code

Source: Sommerville, I. (2007)Slide6

Scattering example – patient records

6

The highlighted operations implement secondary concerns for the system, such as keeping patient and consultant details anonymous

If the policy regarding anonymity changed, we would need to recode each version of

anonymise

() throughout the system

Source: Sommerville, I. (2007)Slide7

The AOP approach

Three key stages:

Aspectual

DecomopositionConcern ImplementationAspectual

Recomposition

7Slide8

How are concerns identified?

8

Source:

Laddad

, R. (2003)

A prismSlide9

Concern Types

Functional

Quality

of ServicePolicy

System

Organisational

9

Functional

related to specific functionality to be included in the system

in a train control system, a specific functional concern is train braking

Quality of Service

related to the non-functional behaviour of a system

performance, reliability, availability

Policy

related to the overall policies that govern the use of the system

security, safety, concerns related to business rules

System

related to attributes of the system as a whole

maintainability, configurability

Organisational

related to organisational goals and priorities

producing a system within budget, making use of existing software assets, maintaining the reputation of an organisationSlide10

Concern Classifications

Core

Functional concerns that directly relate to the primary purpose of a system.

SecondaryFunctionality that shares information with the core concernsFunctionality that satisfies NFRs

Cross-cutting

Concerns that apply to the system as a

whole

10Slide11

Cross-cutting example

11

New customer

req.

Customer management req.

Account management

req.

Security

req.

Recovery

req.

Cross-cutting

concerns

Core concerns

Source: Sommerville, I. (2007)Slide12

Implementing Concerns

Core

Classes & Operations

Cross-cutting / SecondaryAspectsAdvice; Join Points; Pointcuts

12Slide13

Aspect

Aspects are similar to classes in that they can:

include data members and operations

have access specificationsdeclare themselves to be abstractextend classes and abstract aspects and implement interfaces

be embedded inside classes and interfaces as nested aspects

They are dissimilar in that they cannot:

be directly instantiatedinherit from concrete aspects

be marked as privileged

13Slide14

Join Point

Any identifiable execution point in a system

A call to a method

The method’s executionAssignment to a variableReturn statementObject construction

Conditional check

Comparison

Exception handlerLoopsNot all may be exposed by each AOP language

AspectJ

does not expose loops

14Slide15

Pointcut

Pointcuts

capture, or identify, one or more join

points&& ||Need not be given a name

Anonymous

pointcuts

must be specified as part of advice

Can include wildcards

15Slide16

Advice

The code to be executed at a join point

The join point must have been selected by a

pointcutCan be defined as:Before

After

Around

16Slide17

O-O Hello World

17

>

javac

MessageCommunicator.java Test.java

> java test

Wanna

learn

AspectJ

Harry, having fun?Slide18

A-O Hello World

18

>

ajc

MessageCommunicator.java MannersAspect.java Test.java

> java Test

Hello!

Wanna

learn

AspectJ

?

Hello! Harry, having fun?

pointcut

adviceSlide19

A-O Hello World 2

19

>

ajc

MessageCommunicator.java MannersAspect.java Hindi Salutation.java Test.java

> java Test

Hello!

Wanna

learn

AspectJ

?

Hello! Harry-

ji

, having fun?Slide20

Another aspect example

20Slide21

How do we get a working program?

21

Source:

Laddad

, R. (2003)Slide22

Benefits of AOP

Cleaner responsibilities of the individual module

Higher modularisation

Easier system evolution

Late binding of design decisions

More code reuse

Improve time-to-marketReduced costs of feature implementation

22Slide23

Realities of AOP

Program flow is hard to follow

Doesn’t solve any new problems

Breaks encapsulation

23Slide24

Terms to remember

Advice

the code implementing a concern

Aspectprogram abstraction defining a cross-cutting concern. Includes a definition of one or more

pointcuts

and the advice associated with that concernJoin pointan event in a program where the advice associated with an aspect may be executed

Join point model

set of events referenced in a

pointcut

Pointcut

aspect statement defining join points where the associated aspect advice should be executed

Weaving

incorporation of advice code at specified join points by an aspect weaver

24Slide25

Useful Sources

Books

Laddad

, R. (2003), AspectJ in Action, Manning Publications Co.Sommerville, I. (2007), Software Engineering, 8

th

edition, Pearson Education Ltd.

Online

The

AspectJ

Project -

http://www.eclipse.org/aspectj

/

Video

GoogleTechTalks

(2007),

Aspect Oriented Programming: Radical Research in

Modularity. Available at:

http://www.youtube.com/watch?v=cq7wpLI0hco

25