20
Aspect Oriented Development Alex Beatty

Aspect Oriented Development

  • Upload
    yasuo

  • View
    24

  • Download
    0

Embed Size (px)

DESCRIPTION

Aspect Oriented Development. Alex Beatty. Introduction. Purpose Cross-cutting Concerns Join Points, Pointcuts , and Advices Weaving Invasive vs. Non-Invasive Static vs. Dynamic. Purpose. What is a cross-cutting concern? Examples Reduction of code tangling and code scattering - PowerPoint PPT Presentation

Citation preview

Page 1: Aspect Oriented Development

Aspect Oriented Development

Alex Beatty

Page 2: Aspect Oriented Development

Purpose Cross-cutting Concerns

Join Points, Pointcuts, and Advices Weaving

Invasive vs. Non-Invasive Static vs. Dynamic

Introduction

Page 3: Aspect Oriented Development

What is a cross-cutting concern? Examples

Reduction of code tangling and code scattering

Abstraction Obliviousness

Expert Development Object Reuse

Purpose

Page 4: Aspect Oriented Development

Join Point - Point in the base code that aspect code can utilized Examples

A method being called A method’s code being run Initialization

Join Points

Page 5: Aspect Oriented Development

User defined join point(s) to utilize aspect code with AspectJ examples

execution(!static * (Class1 || ClassA).*(..)); call(void Set*(int)); Explanation

Pointcuts

Page 6: Aspect Oriented Development

Basically a function before, after, and around key words

around has a special proceed() function Has access to some information from base

code Function name, parameters, return type, return

value

Advice

Page 7: Aspect Oriented Development

Static vs dynamic Compile-time vs load- or run-time

Invasive vs non-invasive Directly changing base code or not

Weaving

Page 8: Aspect Oriented Development

Logging Coordination Security Mutual Exclusion

Applications

Page 9: Aspect Oriented Development

Coordination

Init

buyers={ }

Auction.join(id)buyers=buyers union {id}

entry/doexit/

CollectBids

at(JoinTime)/price = Auction.getStartingPrice();buyers.callForProposal(price)

Auction.proposeBid(id,bid)[isFirstBid(id)]/placedBids = placedBids union id

CloseAuction

at(biddingTime)Auction.directBuy(id)

/Auction.decideWinner(&winner, &price)buyers=buyers - winnerbuyers.rejectProposal();winner.acceptProposal(winner,price)

Init

buyers={ }

Auction.join(id)buyers=buyers union {id}

CollectBids

at(JoinTime)/price = Auction.getStartingPrice();buyers.callForProposal(price)

Auction.proposeBid(id,bid)/buyers.callForProposal(bid)

CloseAuction

at(biddingTime)Auction.directBuy(id)

Auction.decideWinner(&winner, &price)buyers.acceptProposal(winner,price)

Silent Single Bid

Public English Style

Page 10: Aspect Oriented Development

Confusion about it’s role Anti-pattern: Action at a distance

Downsides

Page 11: Aspect Oriented Development

Java-based Pointcuts

Can use logical operators Can be named

Advices are formatted like java functions

AspectJ

Page 12: Aspect Oriented Development

pointcut functionExecution(): execution(!static * (Class1 || ClassA).*(..))

Name Join point type Join point specification

AspectJ Pointcuts

Page 13: Aspect Oriented Development

Name Shorter than the pointcut itself Can include parameters to capture access to

an object pointcut setter(Person p): target(p) && …

AspectJ Pointcuts

Page 14: Aspect Oriented Development

Methods and Constructors call(Signature) / execution(Signature)

AspectJ Pointcut Types

//before callPerson.walk();//after call

Private void walk(){//before execution//TODO: write function body//after execution}

Page 15: Aspect Oriented Development

Fields get(Signature) / set(Signature)

E.g. set(int Racer.*)

AspectJ Pointcut Types

private int id;… //before setid = 42;//after set

Page 16: Aspect Oriented Development

Instanceof checks and context exposure this(type or id) / target(type or id) / args(type

or id) E.g. args(newval), target(Racer)

Others http://eclipse.org/aspectj/doc/released/progguide/quick.html#qui

ck-pointcuts

AspectJ Pointcut Types

Page 17: Aspect Oriented Development

void around(Racer r): criticalSection(r){ int i = (int) r.getId(); …proceed(); …} thisJoinPoint

Can be used to get arguments, signature, target, etc thisJoinPoint.getArgs();

AspectJ Advices

Page 18: Aspect Oriented Development

Example of Mutual Exclusion Aspect

Page 19: Aspect Oriented Development

Questions

Page 20: Aspect Oriented Development

[1] Aspect-oriented software development. In Wikipedia. Retrieved October 20, 2013, from http://en.wikipedia.org/wiki/Aspect-oriented_software_development

  [2] Rohit Sethi. “Aspect-Oriented Programming and Security”. Retrieved October 28, 2013, from

http://www.symantec.com/connect/articles/aspect-oriented-programming-and-security   [3] Fuentes, Lidia; Sánchez, Pablo. “Aspect-Oriented Coordination”. In Science Direct. Retrieved from

http://www.sciencedirect.com/science/article/pii/S1571066107004926   [4] Aspect Weaver. In Wikipedia. Retrieved October 28, 2013, from

http://en.wikipedia.org/wiki/Aspect_weaver   [5] Piveta, Eduardo Kessler; Zancanella, Luiz Carlos. “Aspect Weaving Strategies”. In Journal of Universal

Computer Science. Retrieved from http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.2.9460&rep=rep1&type=pdf

  [6] The AspectJ Programming Guide. Retrieved October 28, 2013, from

http://eclipse.org/aspectj/doc/released/progguide/index.html

References