R.st.inf.tu-dresden.de/files/teaching/ss14/cbse/... · 9 !!) !! Ó : System.out.println("foo...

34
CBSE, © Prof. Uwe Aßmann 1 44. Aspect-Oriented Programming with Aspect/J Prof. Dr. Uwe Aßmann Technische Universität Dresden Institut für Software- und Multimediatechnik http://st.inf.tu-dresden.de Version 14-0.9, June 14, 2014 1. The Problem of Crosscutting 2. Aspect-Oriented Programming 3. Composition Operators and Point-Cuts 4. AOSD 5. Evaluation as Composition System Prof. U. Aßmann, CBSE 2 Literature http://www.eclipse.org/aspectj/ http://aosd.net/ [KLM+97] G. Kiczales, J. Lamping, A. Mendhekar, C. Maeda, C. Videira Lopes, J.-M. Loingtier, J. Irwin. Aspect-Oriented Programming. 1997 R. Laddad. Aspect/J in Action. Manning Publishers. 2003. Book with many details and applications of Aspect/J.

Transcript of R.st.inf.tu-dresden.de/files/teaching/ss14/cbse/... · 9 !!) !! Ó : System.out.println("foo...

  • CBSE

    , © P

    rof. U

    we A

    ßman

    n 1

    44. A

    spec

    t-Orie

    nted

    Pro

    gram

    min

    g w

    ith A

    spec

    t/J

    Pro

    f. D

    r. U

    we

    Aßm

    ann

    Tech

    nisc

    he U

    nive

    rsitä

    t Dre

    sden

    In

    stitu

    t für

    Sof

    twar

    e- u

    nd M

    ultim

    edia

    tech

    nik

    http

    ://st

    .inf.t

    u-dr

    esde

    n.de

    V

    ersi

    on 1

    4-0.

    9, J

    une

    14, 2

    014

    1. 

    The

    Pro

    blem

    of C

    ross

    cutti

    ng

    2. 

    Asp

    ect-O

    rient

    ed P

    rogr

    amm

    ing

    3. 

    Com

    posi

    tion

    Ope

    rato

    rs a

    nd

    Poi

    nt-C

    uts

    4. 

    AO

    SD

    5. 

    Eva

    luat

    ion

    as C

    ompo

    sitio

    n S

    yste

    m

    Prof.

    U. A

    ßman

    n, CB

    SE

    2

    Lite

    ratu

    re

    ► 

    http

    ://w

    ww

    .ecl

    ipse

    .org

    /asp

    ectj/

    ► 

    http

    ://ao

    sd.n

    et/

    ► 

    [KLM

    +97]

    G. K

    icza

    les,

    J. L

    ampi

    ng, A

    . Men

    dhek

    ar, C

    . Mae

    da, C

    . V

    idei

    ra L

    opes

    , J.-M

    . Loi

    ngtie

    r, J.

    Irw

    in. A

    spec

    t-Orie

    nted

    P

    rogr

    amm

    ing.

    199

    7 ► 

    R. L

    adda

    d. A

    spec

    t/J in

    Act

    ion.

    Man

    ning

    Pub

    lishe

    rs. 2

    003.

    Boo

    k w

    ith

    man

    y de

    tails

    and

    app

    licat

    ions

    of A

    spec

    t/J.

  • Prof.

    U. A

    ßman

    n, CB

    SE

    3

    Oth

    er li

    tera

    ture

    • C

    . V. L

    opes

    . Asp

    ect-O

    rient

    ed P

    rogr

    amm

    ing:

    An

    His

    toric

    al

    Per

    spec

    tive

    (Wha

    t's in

    a N

    ame?

    ). 20

    02

    http

    ://w

    ww

    .isr.u

    ci.e

    du/te

    ch_r

    epor

    ts/U

    CI-I

    SR

    -02-

    5.pd

    f • 

    G. K

    icza

    les.

    Asp

    ect O

    rient

    ed P

    rogr

    amm

    ing

    - Rad

    ical

    Res

    earc

    h in

    M

    odul

    arity

    . Goo

    gle

    Tech

    Tal

    k, 5

    7 m

    in

    http

    ://vi

    deo.

    goog

    le.c

    om/v

    ideo

    sear

    ch?q

    =Kic

    zale

    s • 

    Jend

    rik J

    ohan

    nes.

    Com

    pone

    nt-B

    ased

    Mod

    el-D

    riven

    Sof

    twar

    e D

    evel

    opm

    ent.

    PhD

    thes

    is, D

    resd

    en U

    nive

    rsity

    of T

    echn

    olog

    y,

    Dec

    embe

    r 201

    0.

    • Je

    ndrik

    Joh

    anne

    s an

    d U

    we

    Aßm

    ann.

    Con

    cern

    -bas

    ed (d

    e)co

    mpo

    sitio

    n of

    mod

    el-d

    riven

    sof

    twar

    e de

    velo

    pmen

    t pro

    cess

    es. I

    n D

    . C

    . Pet

    riu, N

    . Rou

    quet

    te, a

    nd O

    .Hau

    gen,

    edi

    tors

    , MoD

    ELS

    (2),

    volu

    me

    6395

    of L

    ectu

    re N

    otes

    in C

    ompu

    ter S

    cien

    ce, p

    ages

    47-

    62.

    Spr

    inge

    r, 20

    10.

    CBSE

    , © P

    rof. U

    we A

    ßman

    n 4

    44.1

    The

    Pro

    blem

    of C

    ross

    cutti

    ng

  • Prof.

    U. A

    ßman

    n, CB

    SE

    5

    XML

    pars

    ing

    in o

    rg.a

    pach

    e.to

    mca

    t

    Goo

    d m

    odul

    arity

    : Th

    e „r

    ed“

    conc

    ern

    is h

    andl

    ed b

    y co

    de in

    one

    cla

    ss

    [Pic

    ture

    take

    n fr

    om th

    e as

    pect

    j.org

    w

    ebsi

    te]

    Prof.

    U. A

    ßman

    n, CB

    SE

    6

    UR

    L pa

    ttern

    mat

    chin

    g in

    org

    .apa

    che.

    tom

    cat

    Goo

    d m

    odul

    arity

    : Th

    e “r

    ed”

    conc

    ern

    is h

    andl

    ed b

    y co

    de in

    two

    clas

    ses

    rela

    ted

    by in

    herit

    ance

    [Pic

    ture

    take

    n fr

    om th

    e as

    pect

    j.org

    w

    ebsi

    te]

  • Prof.

    U. A

    ßman

    n, CB

    SE

    7

    Logg

    ing

    in o

    rg.a

    pach

    e.to

    mca

    t

    BA

    D m

    odul

    arity

    : Th

    e co

    ncer

    n is

    han

    dled

    by

    code

    that

    is s

    catte

    red

    over

    alm

    ost a

    ll cl

    asse

    s

    [Pic

    ture

    take

    n fr

    om th

    e as

    pect

    j.org

    w

    ebsi

    te]

    Prof.

    U. A

    ßman

    n, CB

    SE

    8

    Com

    paris

    on

    Bad

    mod

    ular

    ity

    ► 

    scat

    terin

    g –

    code

    add

    ress

    ing

    one

    conc

    ern

    is s

    prea

    d ar

    ound

    in

    the

    code

    ► 

    “man

    y pl

    aces

    in th

    e co

    de a

    re

    colo

    red

    with

    the

    colo

    r of t

    he

    conc

    ern”

    ► 

    tang

    ling

    – co

    de in

    one

    regi

    on

    addr

    esse

    s m

    ultip

    le c

    once

    rns

    ► 

    “one

    pla

    ces

    in th

    e co

    de is

    col

    ored

    w

    ith th

    e co

    lors

    of m

    any

    conc

    erns

    ► 

    Sca

    tterin

    g an

    d ta

    nglin

    g ap

    pear

    to

    geth

    er; t

    hey

    desc

    ribe

    diffe

    rent

    fa

    cets

    of t

    he s

    ame

    prob

    lem

    ■ 

    redu

    ndan

    t cod

    e ■ 

    diffi

    cult

    to re

    ason

    abo

    ut

    ■ di

    fficu

    lt to

    cha

    nge

    Goo

    d M

    odul

    arity

    ► 

    sepa

    rate

    d –

    impl

    emen

    tatio

    n of

    a

    conc

    ern

    can

    be tr

    eate

    d as

    re

    lativ

    ely

    sepa

    rate

    ent

    ity

    ► 

    loca

    lized

    – im

    plem

    enta

    tion

    of

    a co

    ncer

    n ap

    pear

    s in

    one

    par

    t of

    pro

    gram

    ► 

    mod

    ular

    – a

    bove

    + h

    as a

    cl

    ear,

    wel

    l def

    ined

    inte

    rface

    to

    rest

    of s

    yste

    m

  • Prof.

    U. A

    ßman

    n, CB

    SE

    9

    A fi

    rst e

    xam

    ple

    for s

    catte

    ring

    ► 

    Eve

    ry c

    all t

    o fo

    o is

    pre

    cede

    d by

    a lo

    g ca

    ll (s

    catte

    ring)

    ► 

    Obs

    erve

    the

    gree

    n co

    lor o

    f the

    con

    cern

    “log

    ging

    :

    System.out.println("foo called");

    Helper.foo(n/3);

    :

    :

    System.out.println("foo called");

    Helper.foo(i+j+k);

    :

    :

    System.out.println("foo called");

    Helper.foo(x);

    :

    class Helper {

    :

    public static void foo(int n) {

    }

    :

    }

    Prof.

    U. A

    ßman

    n, CB

    SE

    10

    Cla

    ssic

    Sol

    utio

    n: R

    efac

    torin

    g of

    Sca

    ttere

    d C

    alls

    ► 

    Pro

    cedu

    res

    can

    mod

    ular

    ize

    this

    cas

    e (u

    nles

    s lo

    gs u

    se c

    allin

    g co

    ntex

    t) ► 

    Sca

    ttere

    d ca

    lls c

    an b

    e re

    fact

    ored

    into

    cal

    led

    proc

    edur

    es

    :

    Helper.foo(n/3);

    :

    :

    Helper.foo(i+j+k);

    :

    :

    Helper.foo(x);

    :

    class Helper {

    :

    public static void foo(int n) {

    System.out.println("foo called");

    }

    :

    }

  • Prof.

    U. A

    ßman

    n, CB

    SE

    11

    A s

    econ

    d ex

    ampl

    e of

    S&

    T

    ► 

    all s

    ubcl

    asse

    s ha

    ve a

    n id

    entic

    al

    met

    hod

    • 

    inhe

    ritan

    ce c

    an m

    odul

    ariz

    e th

    is

    • R

    efac

    torin

    g m

    oveU

    pMet

    hod

    2 Po

    int

    getX

    ()

    getY

    ()

    setX

    (int)

    setY

    (int)

    mov

    eBy(

    int,

    int)

    draw

    ()

    refre

    sh()

    Line

    getP

    1()

    getP

    2()

    setP

    1(P

    oint

    ) se

    tP2(

    Poi

    nt)

    mov

    eBy(

    int,

    int)

    draw

    ()

    refre

    sh()

    Figu

    reEl

    emen

    t

    mov

    eBy(

    int,

    int)

    2 Po

    int

    getX

    ()

    getY

    ()

    setX

    (int)

    setY

    (int)

    mov

    eBy(

    int,

    int)

    draw

    ()

    refre

    sh()

    Line

    getP

    1()

    getP

    2()

    setP

    1(P

    oint

    ) se

    tP2(

    Poi

    nt)

    mov

    eBy(

    int,

    int)

    draw

    ()

    refre

    sh()

    Figu

    reEl

    emen

    t

    mov

    eBy(

    int,

    int)

    2 Po

    int

    getX

    ()

    getY

    ()

    setX

    (int)

    setY

    (int)

    mov

    eBy(

    int,

    int)

    draw

    ()

    Line

    getP

    1()

    getP

    2()

    setP

    1(P

    oint

    ) se

    tP2(

    Poi

    nt)

    mov

    eBy(

    int,

    int)

    draw

    ()

    Figu

    reEl

    emen

    t

    mov

    eBy(

    int,

    int)

    refre

    sh()

    Prof.

    U. A

    ßman

    n, CB

    SE

    12

    A F

    inal

    Exa

    mpl

    e of

    S&

    T in

    the

    Impl

    emen

    tatio

    n of

    Met

    hods

    2 Po

    int

    getX

    ()

    getY

    ()

    setX

    (int)

    setY

    (int)

    mov

    eBy(

    int,

    int)

    draw

    ()

    Line

    getP

    1()

    getP

    2()

    setP

    1(P

    oint

    ) se

    tP2(

    Poi

    nt)

    mov

    eBy(

    int,

    int)

    draw

    ()

    Figu

    reEl

    emen

    t

    mov

    eBy(

    int,

    int)

    refre

    sh()

    Som

    e sc

    atte

    rings

    can

    not e

    asily

    be

    refa

    ctor

    ed.

    Exa

    mpl

    e:

    All

    impl

    emen

    tatio

    ns o

    f th

    ese

    met

    hods

    end

    with

    ca

    ll to

    : Display.update();

  • Prof.

    U. A

    ßman

    n, CB

    SE

    13

    Nee

    ds A

    OP

    for a

    Sol

    utio

    n

    Dis

    play

    Upd

    atin

    g

    2 Po

    int

    getX

    ()

    getY

    ()

    setX

    (int)

    setY

    (int)

    mov

    eBy(

    int,

    int)

    draw

    ()

    Line

    getP

    1()

    getP

    2()

    setP

    1(P

    oint

    ) se

    tP2(

    Poi

    nt)

    mov

    eBy(

    int,

    int)

    draw

    ()

    Figu

    reEl

    emen

    t

    mov

    eBy(

    int,

    int)

    refre

    sh()

    after(): call(void FigureElement+.set*(..))

    || call(void FigureElement.moveBy(int, int))

    {

    Display.update();

    }

    after(): call(void FigureElement+.set*(..))

    || call(void FigureElement.moveBy

    (int, int))

    {

    Display.update();

    }

    Aspe

    ct: a

    sepa

    rate

    hype

    rslice

    s with

    conc

    ern m

    appin

    g (cr

    ossc

    ut re

    lation

    )

    Prof.

    U. A

    ßman

    n, CB

    SE

    14

    Cro

    sscu

    t Gra

    phs

    • C

    ross

    cuts

    are

    repr

    esen

    ted

    by c

    ross

    cut g

    raph

    s be

    twee

    n co

    re a

    nd

    aspe

    ct

    • P

    oint

    cut s

    peci

    ficat

    ions

    spe

    cify

    cro

    sscu

    t gra

    phs

    Cor

    e A

    spec

    t

    Cro

    sscu

    t gr

    aph

    Poi

    ntcu

    t sp

    ecifi

    catio

    n

  • CBSE

    , © P

    rof. U

    we A

    ßman

    n 15

    44.2

    CSS

    as

    Dec

    lara

    tive

    Asp

    ect-O

    rient

    ed L

    angu

    age

    Cro

    sscu

    t gra

    ph a

    s ex

    ampl

    e be

    twee

    n co

    re s

    truct

    ure

    and

    attri

    bute

    s (c

    olor

    s)

    CBSE

    , © P

    rof. U

    we A

    ßman

    n 16

    44.2

    Asp

    ect-O

    rient

    ed P

    rogr

    amm

    ing

  • Prof.

    U. A

    ßman

    n, CB

    SE

    17

    The

    AO

    P Id

    ea

    ► 

    Cro

    sscu

    tting

    (sca

    tterin

    g an

    d ta

    nglin

    g) is

    inhe

    rent

    in c

    ompl

    ex

    syst

    ems

    ■ Th

    e “ty

    rann

    y of

    the

    dom

    inan

    t dec

    ompo

    sitio

    n”

    ■ C

    ross

    cutti

    ng c

    once

    rns

    have

    a c

    lear

    pur

    pose

    Wha

    t ■ 

    have

    som

    e re

    gula

    r int

    erac

    tion

    poin

    ts

    Whe

    re

    ► 

    AO

    P p

    ropo

    ses

    to c

    aptu

    re c

    ross

    cutti

    ng c

    once

    rns

    expl

    icitl

    y...

    ■ in

    a m

    odul

    ar w

    ay w

    ith c

    ore

    com

    pone

    nts

    and

    aspe

    ct c

    ompo

    nent

    s

    ► 

    AO

    P im

    prov

    es V

    iew

    -Bas

    ed P

    rogr

    amm

    ing

    ■ A

    OP

    als

    o re

    lies

    on o

    pen

    defin

    ition

    s. A

    cor

    e pr

    ogra

    m is

    ope

    n in

    any

    of i

    ts jo

    in

    poin

    ts. J

    oin

    poin

    ts s

    peci

    fy th

    e “p

    oint

    s of

    ext

    ensi

    on”

    ■ B

    eyon

    d na

    me

    mer

    ging

    (ope

    n de

    finiti

    ons)

    , cro

    ss-c

    uts

    (cro

    ss-c

    uttin

    g re

    latio

    nshi

    ps)

    can

    be d

    efin

    ed s

    uch

    that

    man

    y de

    finiti

    ons

    are

    exte

    nded

    by

    an e

    xten

    sion

    ■ 

    An

    “asp

    ect”

    is a

    gen

    eral

    ized

    con

    stru

    ctiv

    e hy

    pers

    lice

    whi

    ch c

    an e

    xten

    d m

    any

    open

    de

    finiti

    ons,

    whi

    le a

    nor

    mal

    vie

    w u

    sual

    ly e

    xten

    ds o

    nly

    one

    open

    def

    initi

    on

    Prof.

    U. A

    ßman

    n, CB

    SE

    18

    The

    AO

    P Id

    ea (2

    )

    ► 

    Asp

    ects

    are

    sep

    arat

    e, in

    depe

    nden

    t hyp

    ersl

    ices

    , in

    whi

    ch a

    cro

    sscu

    tting

    co

    ncer

    n m

    appi

    ng re

    late

    s fra

    gmen

    t gro

    ups

    (adv

    ices

    ) to

    conc

    erns

    ► 

    Wea

    ving

    des

    crib

    es th

    e co

    mpo

    sitio

    n, e

    xten

    ding

    a c

    ore

    prog

    ram

    at j

    oin

    poin

    ts

    ► 

    At s

    oftw

    are

    deve

    lopm

    ent t

    ime,

    asp

    ects

    and

    cla

    sses

    are

    kep

    t as

    two,

    sep

    arat

    e di

    men

    sion

    s.

    ► 

    At r

    un-ti

    me,

    bot

    h di

    men

    sion

    nee

    d to

    be

    com

    bine

    d in

    som

    e w

    ay fo

    r obt

    aini

    ng th

    e fin

    al p

    rodu

    ct.

    ► 

    Wea

    ving

    is n

    on-s

    ymm

    etric

    com

    posi

    tion

    (hyp

    ersl

    ice

    com

    posi

    tion

    is

    sym

    met

    ric)

    Wea

    ving

    Aspe

    ct cla

    sses

    (fr

    agme

    nts)

    Base

    prog

    ram

    (core

    ) Jo

    in po

    ints

    Cros

    scut

    grap

    h(p

    ointcu

    ts)

  • Prof.

    U. A

    ßman

    n, CB

    SE

    19

    Asp

    ects

    are

    Wov

    en b

    y In

    terp

    reta

    tion

    of th

    e C

    ross

    cut G

    raph

    s • 

    Cro

    sscu

    t gra

    phs

    are

    inte

    rpre

    ted

    to in

    sert

    advi

    ce fr

    agm

    ents

    into

    cor

    e jo

    inpo

    ints

    Cor

    e A

    spec

    t C

    ross

    cut

    grap

    h

    Poi

    ntcu

    t sp

    ecifi

    catio

    n

    Pat

    ched

    Cor

    e

    Prof.

    U. A

    ßman

    n, CB

    SE

    20

    Cro

    sscu

    t Gra

    phs

    in V

    iew

    -Bas

    ed P

    rogr

    amm

    ing

    • C

    ross

    cut g

    raph

    s in

    vie

    w-b

    ased

    pro

    gram

    min

    g ar

    e in

    ject

    ive

    (Vie

    w c

    an

    exte

    nd o

    nly

    one

    open

    def

    initi

    on, b

    ut o

    pen

    defin

    ition

    s ca

    n be

    ex

    tend

    ed b

    y m

    any

    view

    s)

    • Th

    is s

    olve

    s ta

    nglin

    g • 

    Cor

    e po

    sitio

    ns a

    re m

    ulti-

    colo

    red

    Cor

    e Vi

    ew

    Cro

    sscu

    t gr

    aph

    Poi

    ntcu

    t sp

    ecifi

    catio

    n

  • Prof.

    U. A

    ßman

    n, CB

    SE

    21

    Asp

    ects

    allo

    w fo

    r Gen

    eral

    Cro

    sscu

    t Gra

    phs

    • C

    ross

    cuts

    are

    non

    -inje

    ctiv

    e, a

    spec

    ts c

    an e

    xten

    d se

    vera

    l ope

    n de

    finiti

    ons

    • Th

    is s

    imul

    ates

    sca

    tterin

    g • 

    Asp

    ect f

    ragm

    ents

    (adv

    ices

    ) are

    mul

    tiply

    use

    d

    Cor

    e A

    spec

    t

    Cro

    sscu

    t gr

    aph

    Poi

    ntcu

    t sp

    ecifi

    catio

    n

    Prof.

    U. A

    ßman

    n, CB

    SE

    22

    Asp

    ectJ

    : a W

    eave

    r for

    Jav

    a

    ► 

    Firs

    t pro

    duct

    ion-

    qual

    ity A

    OP

    -tech

    nolo

    gy

    ► 

    Allo

    ws

    spec

    ifyin

    g hy

    pers

    lices

    for c

    ross

    cutti

    ng c

    once

    rns

    as s

    epar

    ate

    entit

    ies:

    Asp

    ects

    ■ 

    Stat

    ic jo

    in p

    oint

    s ar

    e co

    de p

    ositi

    ons,

    hoo

    ks, o

    pen

    for e

    xten

    sion

    ■ 

    Dyn

    amic

    join

    poi

    nts

    are

    som

    e po

    ints

    in th

    e ex

    ecut

    ion

    trace

    of a

    n ap

    plic

    atio

    n,

    open

    for e

    xten

    sion

    ■ 

    Poin

    tcut

    : a s

    et o

    f log

    ical

    ly re

    late

    d jo

    in p

    oint

    s ■ 

    Adv

    ice:

    a fr

    agm

    ent w

    ith b

    ehav

    ior t

    hat s

    houl

    d be

    com

    e ac

    tive

    whe

    neve

    r a d

    ynam

    ic

    join

    poi

    nt is

    enc

    ount

    ered

    ■ 

    Wea

    ving

    : a

    tech

    nolo

    gy fo

    r brin

    ging

    asp

    ects

    and

    bas

    e co

    de to

    geth

    er

    // aspects are hyperslices plus integrated concern mapping

    aspect <concern> {

    // introductions: fragments added to classes of the core

    // advices: fragments for extensions of methods

    // pointcuts: concern mapping from advices to

    // joinpoints of the core

    }

  • Prof.

    U. A

    ßman

    n, CB

    SE

    23

    Exam

    ple:

    A S

    impl

    e Fi

    gure

    Edi

    tor

    oper

    atio

    ns th

    at m

    ove

    elem

    ents

    fact

    ory

    met

    hods

    D

    ispl

    ay

    *

    2 Po

    int

    getX

    ()

    getY

    ()

    setX

    (int)

    setY

    (int)

    mov

    eBy(

    int,

    int)

    Line

    getP

    1()

    getP

    2()

    setP

    1(P

    oint

    ) se

    tP2(

    Poi

    nt)

    mov

    eBy(

    int,

    int)

    Figu

    re

    mak

    ePoi

    nt(..

    ) m

    akeL

    ine(

    ..)

    Figu

    reEl

    emen

    t

    mov

    eBy(

    int,

    int)

    Prof.

    U. A

    ßman

    n, CB

    SE

    24

    Exam

    ple:

    A S

    impl

    e Fi

    gure

    Edi

    tor (

    Java

    )

    class Line implements FigureElement{

    private Point p1, p2;

    Point getP1() { return p1; }

    Point getP2() { return p2; }

    void setP1(Point p1) { this.p1 = p1; }

    void setP2(Point p2) { this.p2 = p2; }

    void moveBy(int dx, int dy) { ... }

    }

    class Point implements FigureElement {

    private int x = 0, y = 0;

    int getX() { return x; }

    int getY() { return y; }

    void setX(int x) { this.x = x; }

    void setY(int y) { this.y = y; }

    void moveBy(int dx, int dy) { ... }

    }

  • Prof.

    U. A

    ßman

    n, CB

    SE

    25

    Dis

    play

    Upd

    atin

    g

    ► 

    Col

    lect

    ion

    of fi

    gure

    ele

    men

    ts

    ■ th

    at m

    ove

    perio

    dica

    lly

    ■ m

    ust r

    efre

    sh th

    e di

    spla

    y as

    nee

    ded

    we

    will

    ass

    ume

    just

    a

    sing

    le d

    ispl

    ay

    Prof.

    U. A

    ßman

    n, CB

    SE

    26

    a Li

    ne

    a Po

    int

    Asp

    ect/J

    Dyn

    amic

    Joi

    n Po

    ints

    (Dyn

    amic

    H

    ooks

    )

    ► 

    A d

    ynam

    ic jo

    in p

    oint

    is a

    hoo

    k (e

    xten

    sion

    poi

    nt) i

    n th

    e ex

    ecut

    ion

    trace

    of a

    pro

    gram

    , als

    o in

    dyn

    amic

    cal

    l gra

    ph

    retu

    rnin

    g or

    th

    row

    ing

    disp

    atch

    disp

    atch

    a m

    etho

    d ca

    ll re

    turn

    ing

    or th

    row

    ing

    a m

    etho

    d ex

    ecut

    ion

    retu

    rnin

    g or

    thro

    win

    g a

    met

    hod

    exec

    utio

    n

    line.moveBy(2, 2)

  • Prof.

    U. A

    ßman

    n, CB

    SE

    27

    Dyn

    amic

    Joi

    n Po

    int T

    erm

    inol

    ogy

    ► 

    The

    join

    -poi

    nt m

    odel

    of A

    spec

    t/J d

    efin

    es s

    ever

    al ty

    pes

    of jo

    in

    poin

    ts (j

    oin-

    poin

    t typ

    es)

    ■ m

    etho

    d &

    con

    stru

    ctor

    cal

    l ■ 

    met

    hod

    & c

    onst

    ruct

    or e

    xecu

    tion

    ■ fie

    ld g

    et &

    set

    ■ 

    exce

    ptio

    n ha

    ndle

    r exe

    cutio

    n ■ 

    stat

    ic &

    dyn

    amic

    initi

    aliz

    atio

    n a Li

    ne

    disp

    atch

    met

    hod

    call

    join

    poi

    nts

    Met

    hod

    body

    ex

    ecut

    ion

    join

    poi

    nts

    Prof.

    U. A

    ßman

    n, CB

    SE

    28

    Join

    Poi

    nt T

    erm

    inol

    ogy

    a Po

    int

    a Li

    ne

    all j

    oin

    poin

    ts o

    n th

    is s

    lide

    are

    with

    in th

    e co

    ntro

    l flo

    w re

    gion

    of

    this

    join

    poi

    nt

    a Po

    int

    line.moveBy(2, 2)

  • Prof.

    U. A

    ßman

    n, CB

    SE

    29

    Prim

    itive

    Poi

    ntcu

    ts

    ► 

    A p

    oint

    cut i

    s an

    spe

    cific

    atio

    n ad

    dres

    sing

    a s

    et o

    f joi

    n po

    ints

    that

    : ■ 

    can

    mat

    ch o

    r not

    mat

    ch a

    ny g

    iven

    join

    poi

    nt a

    nd

    ■ op

    tiona

    lly, c

    an p

    ull o

    ut s

    ome

    of th

    e va

    lues

    at t

    hat j

    oin

    poin

    t ■ 

    “a m

    eans

    of i

    dent

    ifyin

    g jo

    in p

    oint

    s”

    ► E

    xam

    ple:

    call(void Line.setP1(Point))

    mat

    ches

    if th

    e jo

    in p

    oint

    is a

    met

    hod

    call

    with

    this

    sig

    natu

    re

    Prof.

    U. A

    ßman

    n, CB

    SE

    30

    Poin

    tcut

    Com

    posi

    tion

    ► 

    Poi

    ntcu

    ts a

    re lo

    gica

    l exp

    ress

    ions

    in A

    spec

    t/J, t

    hey

    com

    pose

    like

    pr

    edic

    ates

    , usi

    ng &

    &, |

    | and

    !

    whe

    neve

    r a L

    ine

    rece

    ives

    a

    “vo

    id s

    etP

    1(P

    oint

    )” o

    r “vo

    id s

    etP

    2(P

    oint

    )” m

    etho

    d ca

    ll or

    a “v

    oid

    Line

    .set

    P2(

    Poi

    nt)”

    cal

    l

    a “v

    oid

    Line

    .set

    P1(

    Poi

    nt)”

    cal

    l

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point));

  • Prof.

    U. A

    ßman

    n, CB

    SE

    31

    Use

    r-D

    efin

    ed P

    oint

    cuts

    ► 

    Use

    r-de

    fined

    (nam

    ed) p

    oint

    cuts

    can

    be

    used

    in th

    e sa

    me

    way

    as

    prim

    itive

    poi

    ntcu

    ts

    pointcut move():

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point));

    nam

    e pa

    ram

    eter

    s

    mor

    e on

    par

    amet

    ers

    and

    how

    poi

    ntcu

    t can

    ex

    pose

    val

    ues

    at jo

    in

    poin

    ts in

    a fe

    w s

    lides

    Prof.

    U. A

    ßman

    n, CB

    SE

    32

    pointcut move():

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point));

    after() returning: move() {

    <code here runs after each move>

    }

    Afte

    r Adv

    ice

    ► 

    An

    afte

    r adv

    ice

    is a

    frag

    men

    t des

    crib

    ing

    the

    actio

    n to

    take

    afte

    r co

    mpu

    tatio

    n un

    der j

    oin

    poin

    ts

    a Li

    ne

    afte

    r adv

    ice

    runs

    “o

    n th

    e w

    ay b

    ack

    out”

  • Prof.

    U. A

    ßman

    n, CB

    SE

    33

    A S

    impl

    e A

    spec

    t

    • A

    n as

    pect

    def

    ines

    a s

    peci

    al c

    lass

    col

    lect

    ing

    all f

    ragm

    ents

    rela

    ted

    to

    one

    conc

    ern

    and

    whi

    ch w

    ill c

    ross

    cut c

    ore

    clas

    ses

    • W

    ith o

    ne o

    r sev

    eral

    adv

    ices

    (fra

    gmen

    ts p

    lus

    com

    posi

    tion

    expr

    essi

    on)

    • W

    ith a

    t lea

    st o

    ne p

    oint

    cut e

    xpre

    ssin

    g th

    e cr

    ossc

    ut g

    raph

    aspect DisplayUpdating {

    pointcut move():

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point));

    after() returning: move() {

    Display.update();

    }

    }

    Prof.

    U. A

    ßman

    n, CB

    SE

    34

    With

    and

    With

    out A

    spec

    tJ

    ■ D

    ispl

    ay.u

    pdat

    e ca

    lls a

    re ta

    ngle

    d th

    roug

    h th

    e co

    de

    ■ “w

    hat i

    s go

    ing

    on” i

    s le

    ss e

    xplic

    it

    class Line {

    private Point p1, p2;

    Point getP1() { return p1; }

    Point getP2() { return p2; }

    void setP1(Point p1) {

    this.p1 = p1;

    // join point

    }

    void setP2(Point p2) {

    this.p2 = p2;

    // join point

    }

    }

    class Line {

    private Point p1, p2;

    Point getP1() { return p1; }

    Point getP2() { return p2; }

    void setP1(Point p1) {

    this.p1 = p1;

    Display.update();

    }

    void setP2(Point p2) {

    this.p2 = p2;

    Display.update();

    }

    }

    aspect DisplayUpdating {

    pointcut move():

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point));

    after() returning: move() {

    Display.update();

    }

    }

    Wea

    ver

  • Prof.

    U. A

    ßman

    n, CB

    SE

    35

    A m

    ulti-

    clas

    s as

    pect

    With

    poi

    ntcu

    ts c

    uttin

    g ac

    ross

    mul

    tiple

    cla

    sses

    aspect DisplayUpdating {

    pointcut move():

    call(void FigureElement.moveBy(int, int)) ||

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)) ||

    call(void Point.setX(int)) ||

    call(void Point.setY(int));

    after() returning: move() {

    Display.update();

    }

    }

    Prof.

    U. A

    ßman

    n, CB

    SE

    36

    pointcut move(FigureElement figElt):

    target(figElt) &&

    (call(void FigureElement.moveBy(int, int)) ||

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)) ||

    call(void Point.setX(int)) ||

    call(void Point.setY(int)));

    after(FigureElement fe) returning: move(fe) {

    <fe is bound to the figure element>

    } Usi

    ng v

    alue

    s at

    join

    poi

    nts

    ► 

    A p

    oint

    cut c

    an e

    xplic

    itly

    expo

    se c

    erta

    in ru

    n-tim

    e va

    lues

    in

    para

    met

    ers

    ► 

    An

    advi

    ce c

    an u

    se th

    e ex

    pose

    d va

    lue

    P

    oint

    cut

    Par

    amet

    er

    defin

    ed a

    nd

    used

    Poi

    ntcu

    t par

    amet

    er

    advi

    ce p

    aram

    eter

    s

  • Prof.

    U. A

    ßman

    n, CB

    SE

    37

    Para

    met

    ers

    of u

    ser-

    defin

    ed p

    oint

    cut d

    esig

    nato

    r

    ► V

    aria

    ble

    is b

    ound

    by

    user

    -def

    ined

    poi

    ntcu

    t dec

    lara

    tion

    ■ P

    oint

    cut s

    uppl

    ies

    valu

    e fo

    r var

    iabl

    e ■ 

    Val

    ue is

    ava

    ilabl

    e to

    all

    user

    s of

    use

    r-de

    fined

    poi

    ntcu

    t

    poin

    tcut

    par

    amet

    ers

    pointcut move(Line l):

    target(l) &&

    (call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)));

    after(Line line): move(line) {

    <line is bound to the line>

    }

    type

    d va

    riabl

    e in

    pla

    ce o

    f typ

    e na

    me

    Prof.

    U. A

    ßman

    n, CB

    SE

    38

    Para

    met

    ers

    of a

    dvic

    e

    ► V

    aria

    ble

    is b

    ound

    by

    advi

    ce d

    ecla

    ratio

    n ■ 

    Poi

    ntcu

    t sup

    plie

    s va

    lue

    for v

    aria

    ble

    ■ V

    alue

    is a

    vaila

    ble

    in a

    dvic

    e bo

    dy

    pointcut move(Line l):

    target(l) &&

    (call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)));

    after(Line line): move(line) {

    <line is bound to the line>

    }

    Poi

    ntcu

    t par

    amet

    er

    advi

    ce p

    aram

    eter

    s

  • Prof.

    U. A

    ßman

    n, CB

    SE

    39

    Expl

    aini

    ng p

    aram

    eter

    s…

    ► Va

    lue

    is ‘p

    ulle

    d’

    ■ rig

    ht to

    left

    acro

    ss ‘:

    le

    ft si

    de :

    right

    sid

    e ■ 

    from

    poi

    ntcu

    ts to

    use

    r-de

    fined

    poi

    ntcu

    ts

    ■ fro

    m p

    oint

    cuts

    to a

    dvic

    e, a

    nd th

    en a

    dvic

    e bo

    dy

    pointcut move(Line l):

    target(l) &&

    (call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)));

    after(Line line): move(line) {

    <line is bound to the line>

    }

    Prof.

    U. A

    ßman

    n, CB

    SE

    40

    Join

    Poi

    nt Q

    ualif

    ier “

    Targ

    et”

    A jo

    in p

    oint

    qua

    lifie

    r doe

    s tw

    o th

    ings

    : • 

    expo

    ses

    info

    rmat

    ion

    from

    the

    cont

    ext o

    f the

    join

    poi

    nt (e

    .g, t

    arge

    t ob

    ject

    of a

    mes

    sage

    ) • 

    test

    s a

    pred

    icat

    e on

    join

    poi

    nts

    (e.g

    ., a

    dyna

    mic

    type

    test

    - an

    y jo

    in p

    oint

    at w

    hich

    targ

    et o

    bjec

    t is

    an in

    stan

    ce o

    f typ

    e na

    me)

    target(<type name> | <formal reference>)

    target(Point)

    target(Line)

    target(FigureElement)

    “any

    join

    poi

    nt” m

    eans

    it m

    atch

    es jo

    in p

    oint

    s of

    all

    kind

    s:

    met

    hod

    & c

    onst

    ruct

    or c

    all j

    oin

    poin

    ts

    met

    hod

    & c

    onst

    ruct

    or e

    xecu

    tion

    join

    poi

    nts

    field

    get

    & s

    et jo

    in p

    oint

    s ex

    cept

    ion

    hand

    ler e

    xecu

    tion

    join

    poi

    nts

    stat

    ic &

    dyn

    amic

    initi

    aliz

    atio

    n jo

    in p

    oint

    s

  • Prof.

    U. A

    ßman

    n, CB

    SE

    41

    pointcut move(FigureElement figElt):

    target(figElt) &&

    (call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)) ||

    call(void Point.setX(int)) ||

    call(void Point.setY(int)));

    after(FigureElement fe): move(fe) {

    <fe is bound to the figure element>

    } Get

    ting

    targ

    et o

    bjec

    t in

    a po

    lym

    orph

    ic p

    oint

    cut

    target(<supertype name>) &&

    ► do

    es n

    ot fu

    rther

    rest

    rict t

    he jo

    in p

    oint

    s ► do

    es p

    ick

    up th

    e ta

    rget

    obj

    ect

    Prof.

    U. A

    ßman

    n, CB

    SE

    42

    Con

    text

    & m

    ultip

    le c

    lass

    es

    aspect DisplayUpdating {

    pointcut move(FigureElement figElt):

    target(figElt) &&

    (call(void FigureElement.moveBy(int, int)) ||

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)) ||

    call(void Point.setX(int)) ||

    call(void Point.setY(int)));

    after(FigureElement fe): move(fe) {

    Display.update(fe);

    }

    }

  • Prof.

    U. A

    ßman

    n, CB

    SE

    43

    class Line {

    private Point p1, p2;

    Point getP1() { return p1; }

    Point getP2() { return p2; }

    void setP1(Point p1) {

    this.p1 = p1;

    Display.update(this);

    }

    void setP2(Point p2) {

    this.p2 = p2;

    Display.update(this);

    }

    }

    class Point {

    private int x = 0, y = 0;

    int getX() { return x; }

    int getY() { return y; }

    void setX(int x) {

    this.x = x;

    Display.update(this);

    }

    void setY(int y) {

    this.y = y;

    Display.update(this);

    }

    }

    With

    out A

    spec

    tJ

    ► 

    no lo

    cus

    of “d

    ispl

    ay u

    pdat

    ing”

    ■ 

    evol

    utio

    n is

    cum

    bers

    ome

    ■ ch

    ange

    s in

    all

    clas

    ses

    ■ ha

    ve to

    trac

    k &

    cha

    nge

    all c

    alle

    rs

    Prof.

    U. A

    ßman

    n, CB

    SE

    44

    With

    Asp

    ectJ

    ► 

    clea

    r dis

    play

    upd

    atin

    g m

    odul

    e ■ 

    all c

    hang

    es in

    sin

    gle

    aspe

    ct

    ■ ev

    olut

    ion

    is m

    odul

    ar

    aspect DisplayUpdating {

    pointcut move(FigureElement figElt):

    target(figElt) &&

    (call(void FigureElement.moveBy(int, int) ||

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)) ||

    call(void Point.setX(int)) ||

    call(void Point.setY(int)));

    after(FigureElement fe) returning: move(fe) {

    Display.update(fe);

    }

    }

    class Line {

    private Point p1, p2;

    Point getP1() { return p1; }

    Point getP2() { return p2; }

    void setP1(Point p1) {

    this.p1 = p1;

    }

    void setP2(Point p2) {

    this.p2 = p2;

    }

    }

    class Point {

    private int x = 0, y = 0;

    int getX() { return x; }

    int getY() { return y; }

    void setX(int x) {

    this.x = x;

    }

    void setY(int y) {

    this.y = y;

    }

    }

  • Prof.

    U. A

    ßman

    n, CB

    SE

    45

    Asp

    ects

    Cro

    sscu

    t Cla

    sses

    aspe

    ct m

    odul

    arity

    cut

    s ac

    ross

    cl

    ass

    mod

    ular

    ity

    Asp

    ect

    Dis

    play

    Upd

    atin

    g

    Dis

    play

    *

    2 Po

    int

    getX

    ()

    getY

    ()

    setX

    (int)

    setY

    (int)

    mov

    eBy(

    int,

    int)

    Line

    getP

    1()

    getP

    2()

    setP

    1(P

    oint

    ) se

    tP2(

    Poi

    nt)

    mov

    eBy(

    int,

    int)

    Figu

    re

    mak

    ePoi

    nt(..

    ) m

    akeL

    ine(

    ..)

    Figu

    reEl

    emen

    t

    mov

    eBy(

    int,

    int) C

    BSE,

    © P

    rof. U

    we A

    ßman

    n 46

    44.3

    Com

    posi

    tion

    Ope

    rato

    rs a

    nd

    Poin

    t-Cut

    s

  • Prof.

    U. A

    ßman

    n, CB

    SE

    47

    Type

    s of

    Adv

    ice

    Com

    posi

    tion

    Ope

    rato

    rs

    ► 

    befo

    re

    bef

    ore

    proc

    eedi

    ng a

    t joi

    n po

    int

    ► 

    afte

    r ret

    urni

    ng a

    val

    ue to

    join

    poi

    nt

    ► 

    afte

    r thr

    owin

    g a

    thro

    wab

    le to

    join

    poi

    nt

    ► 

    afte

    r

    retu

    rnin

    g to

    join

    poi

    nt e

    ither

    way

    ► 

    arou

    nd

    on

    arriv

    al a

    t joi

    n po

    int g

    ets

    expl

    icit

    c

    ontro

    l ove

    r whe

    n an

    d if

    prog

    ram

    pro

    ceed

    s

    Prof.

    U. A

    ßman

    n, CB

    SE

    48

    Exam

    ple:

    Con

    trac

    t che

    ckin

    g w

    ith A

    spec

    ts

    ► 

    Sim

    ple

    appl

    icat

    ion

    of b

    efor

    e/af

    ter/a

    roun

    d co

    mpo

    sitio

    n op

    erat

    ors

    ► 

    pre-

    cond

    ition

    s (a

    ssum

    ptio

    ns)

    ■ ch

    eck

    whe

    ther

    par

    amet

    er is

    val

    id

    ► 

    post

    -con

    ditio

    ns (g

    uara

    ntee

    s)

    ■ ch

    eck

    whe

    ther

    val

    ues

    wer

    e se

    t

    ► 

    Inva

    riant

    s

    ► 

    Che

    ck c

    ondi

    tions

    that

    sho

    uld

    be tr

    ue e

    very

    whe

    re

    ► 

    cond

    ition

    enf

    orce

    men

    t ■ 

    forc

    e pa

    ram

    eter

    s to

    be

    valid

    and

    con

    sist

    ent

  • Prof.

    U. A

    ßman

    n, CB

    SE

    49

    Pre-

    Con

    ditio

    n (A

    ssum

    ptio

    n)

    usin

    g be

    fore

    adv

    ice

    aspect PointBoundsPreCondition {

    before(int newX):

    call(void Point.setX(int)) && args(newX) {

    assert(newX >= MIN_X);

    assert(newX <= MAX_X);

    }

    before(int newY):

    call(void Point.setY(int)) && args(newY) {

    assert(newY >= MIN_Y);

    assert(newY <= MAX_Y);

    }

    private void assert(boolean v) {

    if ( !v )

    throw new RuntimeException();

    }

    }

    wha

    t fol

    low

    s th

    e ‘:’

    is

    alw

    ays

    a po

    intc

    ut –

    pr

    imiti

    ve o

    r use

    r-de

    fined

    Prof.

    U. A

    ßman

    n, CB

    SE

    50

    Post

    -con

    ditio

    n

    aspect PointBoundsPostCondition {

    after(Point p, int newX) returning:

    call(void Point.setX(int)) && target(p) && args(newX) {

    assert(p.getX() == newX);

    }

    after(Point p, int newY) returning:

    call(void Point.setY(int)) && target(p) && args(newY) {

    assert(p.getY() == newY);

    }

    private void assert(boolean v) {

    if ( !v )

    throw new RuntimeException();

    }

    }

    usin

    g af

    ter a

    dvic

    e

  • Prof.

    U. A

    ßman

    n, CB

    SE

    51

    Con

    ditio

    n en

    forc

    emen

    t

    aspect PointBoundsEnforcement {

    void around(int newX):

    call(void Point.setX(int)) && args(newX) {

    proceed(// before the join point

    clip(newX, MIN_X, MAX_X)

    );

    // after the join point

    System.out.println(“after”);

    }

    void around(int newY):

    call(void Point.setY(int)) && args(newY) {

    proceed(clip(newY, MIN_Y, MAX_Y));

    }

    private int clip(int val, int min, int max) {

    return Math.max(min, Math.min(max, val));

    }

    }

    usin

    g ar

    ound

    adv

    ice

    Prof.

    U. A

    ßman

    n, CB

    SE

    52

    Spec

    ial M

    etho

    ds (H

    ooks

    in A

    dvic

    es)

    ► 

    For e

    ach

    arou

    nd a

    dvic

    e w

    ith th

    e si

    gnat

    ure

    <Tr> around(T1 arg1, T2 arg2, …)

    ► th

    ere

    is a

    spe

    cial

    met

    hod

    with

    the

    sign

    atur

    e <Tr> proceed(T1, T2, …)

    ► 

    avai

    labl

    e on

    ly in

    aro

    und

    advi

    ce, m

    eani

    ng “r

    un w

    hat w

    ould

    hav

    e ru

    n if

    this

    aro

    und

    advi

    ce h

    ad n

    ot b

    een

    defin

    ed”

  • Prof.

    U. A

    ßman

    n, CB

    SE

    53

    Prop

    erty

    -bas

    ed c

    ross

    cutti

    ng (“

    List

    ener

    A

    spec

    ts”)

    ► 

    cros

    scut

    s of

    met

    hods

    with

    a c

    omm

    on p

    rope

    rty

    ■ pu

    blic

    /priv

    ate,

    retu

    rn a

    cer

    tain

    val

    ue, i

    n a

    parti

    cula

    r pac

    kage

    ► 

    logg

    ing,

    deb

    uggi

    ng, p

    rofil

    ing

    ■ lo

    g on

    ent

    ry to

    eve

    ry p

    ublic

    met

    hod

    package

    com.xerox.print;

    public class C1 {

    public void foo() {

    A.doSomething(…);

    }

    }

    package

    com.xerox.scan;

    public class C2 {

    public int frotz() {

    A.doSomething(…);

    }

    public int bar() {

    A.doSomething(…);

    }

    }

    package

    com.xerox.copy;

    public class C3 {

    public String s1() {

    A.doSomething(…);

    }

    }

    Prof.

    U. A

    ßman

    n, CB

    SE

    54

    Prop

    erty

    -bas

    ed c

    ross

    cutti

    ng

    ► 

    cons

    ider

    cod

    e m

    aint

    enan

    ce

    ► 

    anot

    her p

    rogr

    amm

    er a

    dds

    a pu

    blic

    met

    hod

    . i.e

    . ext

    ends

    pub

    lic in

    terfa

    ce –

    this

    cod

    e w

    ill s

    till w

    ork

    ► 

    anot

    her p

    rogr

    amm

    er re

    ads

    this

    cod

    e . 

    “wha

    t’s re

    ally

    goi

    ng o

    n” is

    exp

    licit

    aspect PublicErrorLogging {

    Log log = new Log();

    pointcut publicInterface():

    call(public * com.xerox..*.*(..));

    after() throwing (Error e): publicInterface() {

    log.write(e);

    }

    }

    neat

    ly c

    aptu

    res

    publ

    ic i

    nter

    face

    of

    myp

    acka

    ge

  • Prof.

    U. A

    ßman

    n, CB

    SE

    55

    Wild

    card

    ing

    in p

    oint

    cuts

    target(Point)

    target(graphics.geom.Point)

    target(graphics.geom.*)

    any

    type

    in g

    raph

    ics.

    geom

    target(graphics..*)

    an

    y ty

    pe in

    any

    sub

    -pac

    kage

    of g

    raph

    ics

    call(void Point.setX(int))

    call(public * Point.*(..))

    any

    publ

    ic m

    etho

    d on

    Poi

    nt

    call(public * *(..))

    any

    publ

    ic m

    etho

    d on

    any

    type

    call(void Point.getX())

    call(void Point.getY())

    call(void Point.get*())

    call(void get*())

    any

    gette

    r ca

    ll(Point.new(int, int))

    call(new(..))

    any

    cons

    truct

    or

    “*” i

    s w

    ild c

    ard

    “..” i

    s m

    ulti-

    part

    wild

    car

    d

    Prof.

    U. A

    ßman

    n, CB

    SE

    56

    Oth

    er P

    rimiti

    ve P

    oint

    cuts

    this(<type name>)

    any

    join

    poi

    nt a

    t whi

    ch c

    urre

    ntly

    exe

    cutin

    g ob

    ject

    is a

    n in

    stan

    ce o

    f typ

    e na

    me

    within(<type name>)

    any

    join

    poi

    nt a

    t whi

    ch c

    urre

    ntly

    exe

    cutin

    g co

    de is

    con

    tain

    ed w

    ithin

    type

    na

    me

    withincode(<method/constructor signature>)

    any

    join

    poi

    nt a

    t whi

    ch c

    urre

    ntly

    exe

    cutin

    g co

    de is

    spe

    cifie

    d m

    etho

    d or

    con

    stru

    ctor

    ge

    t(int Point.x)

    set(int Point.x)

    field

    refe

    renc

    e or

    ass

    ignm

    ent j

    oin

    poin

    ts

  • Prof.

    U. A

    ßman

    n, CB

    SE

    57

    Oth

    er P

    rimiti

    ve P

    oint

    cuts

    execution(void Point.setX(int))

    met

    hod/

    cons

    truct

    or e

    xecu

    tion

    join

    poi

    nts

    (act

    ual r

    unni

    ng m

    etho

    d)

    initialization(Point)

    obje

    ct in

    itial

    izat

    ion

    join

    poi

    nts

    staticinitialization(Point)

    clas

    s in

    itial

    izat

    ion

    join

    poi

    nts

    (as

    the

    clas

    s is

    load

    ed)

    cflow(pointcut designator)

    all j

    oin

    poin

    ts w

    ithin

    the

    dyna

    mic

    con

    trol f

    low

    of a

    ny jo

    in p

    oint

    in

    poin

    tcut

    des

    igna

    tor

    cflowbelow(pointcut designator)

    all j

    oin

    poin

    ts w

    ithin

    the

    dyna

    mic

    con

    trol f

    low

    bel

    ow a

    ny jo

    in p

    oint

    in

    poi

    ntcu

    t des

    igna

    tor,

    excl

    udin

    g th

    isJo

    inP

    oint

    Prof.

    U. A

    ßman

    n, CB

    SE

    58

    Exam

    ple:

    Onl

    y to

    p-le

    vel m

    oves

    aspect DisplayUpdating {

    pointcut move(FigureElement fe):

    target(fe) &&

    (call(void FigureElement.moveBy(int, int)) ||

    call(void Line.setP1(Point)) ||

    call(void Line.setP2(Point)) ||

    call(void Point.setX(int)) ||

    call(void Point.setY(int)));

    pointcut topLevelMove(FigureElement fe):

    move(fe) && !cflowbelow(move(FigureElement));

    after(FigureElement fe) returning: topLevelMove(fe) {

    Display.update(fe);

    }

    }

  • Prof.

    U. A

    ßman

    n, CB

    SE

    59

    Asp

    ect/J

    Intr

    oduc

    tions

    • A

    n as

    pect

    can

    intro

    duce

    new

    attr

    ibut

    es a

    nd m

    etho

    ds to

    exi

    stin

    g cl

    asse

    s

    aspect PointObserving {

    private Vector Point.observers = new Vector();

    public static void addObserver(Point p, Screen s){

    p.observers.add(s); }

    public static void removeObserver(Point p, Screen s){

    p.observers.remove(s); }

    pointcut changes(Point p): target(p) && call(void Point.set*(int));

    after(Point p): changes(p) {

    Iterator iter = p.observers.iterator();

    while ( iter.hasNext() ) {

    updateObserver(p, (Screen)iter.next()); }

    }

    static void updateObserver(Point p, Screen s) {

    s.display(p); }

    }

    Prof.

    U. A

    ßman

    n, CB

    SE

    60

    Oth

    er a

    ppro

    ache

    s (1

    )

    ► 

    http

    ://w

    ww

    .aos

    d.ne

    t/ ► 

    Asp

    ectJ

    use

    s co

    mpi

    le-ti

    me

    byte

    code

    wea

    ving

    , ■ 

    but a

    lso

    inse

    rts c

    ode

    that

    mat

    ches

    dyn

    amic

    join

    poi

    nts

    (dyn

    amic

    wea

    ving

    ) ■ 

    supp

    orts

    wea

    ving

    asp

    ects

    to e

    xist

    ing

    *.cl

    ass

    files

    (bas

    ed o

    n B

    CE

    L)

    ► 

    Asp

    ect/J

    was

    take

    n ov

    er b

    y IB

    M a

    s pa

    rt of

    the

    Ecl

    ipse

    pro

    ject

    : ht

    tp://

    ww

    w.e

    clip

    se.o

    rg/a

    spec

    tj A

    spec

    tC+

    + is

    an

    aspe

    ct-o

    rien

    ted

    exte

    nsio

    n to

    the

    C+

    + p

    rogr

    amm

    ing

    lang

    uage

    .

    Asp

    ectJ

    is a

    sea

    mle

    ss a

    spec

    t-or

    ient

    ed e

    xten

    sion

    to

    Java

    tha

    t en

    able

    s th

    e m

    odul

    ar

    impl

    emen

    tatio

    n of

    a w

    ide

    rang

    e of

    cro

    sscu

    ttin

    g co

    ncer

    ns.

    A

    spec

    tWer

    kz is

    a d

    ynam

    ic,

    light

    wei

    ght

    and

    high

    -per

    form

    ant

    AO

    P/AO

    SD

    fra

    mew

    ork

    for

    Java

    .

    JAC

    is a

    Jav

    a fr

    amew

    ork

    for

    aspe

    ct-o

    rien

    ted

    dist

    ribu

    ted

    prog

    ram

    min

    g.

    JBos

    s-A

    OP

    is t

    he J

    ava

    AO

    P ar

    chite

    ctur

    e us

    ed for

    the

    JBO

    SS a

    pplic

    atio

    n se

    rver

    .

    Nan

    nin

    g is

    an

    Asp

    ect

    Orien

    ted

    Fram

    ewor

    k fo

    r Ja

    va b

    ased

    on

    dyna

    mic

    pro

    xies

    and

    asp

    ects

    im

    plem

    ente

    d as

    ord

    inar

    y Ja

    va-c

    lass

    es.

  • Prof.

    U. A

    ßman

    n, CB

    SE

    61

    Oth

    er a

    ppro

    ache

    s (2

    )

    Asp

    ectR

    is a

    spec

    t-or

    ient

    ed p

    rogr

    amm

    ing

    for

    Rub

    y th

    at a

    llow

    s yo

    u to

    wra

    p co

    de

    arou

    nd e

    xist

    ing

    met

    hods

    in y

    our

    clas

    ses.

    A

    spec

    tS is

    an

    early

    prot

    otyp

    e th

    at e

    nabl

    es a

    spec

    t-or

    ient

    ed p

    rogr

    amm

    ing

    in t

    he

    Squ

    eak/

    Sm

    allta

    lk e

    nviron

    men

    t.

    Cae

    sarJ

    is a

    n as

    pect

    -orien

    ted

    prog

    ram

    min

    g la

    ngua

    ge t

    hat

    focu

    sses

    on

    mul

    ti-vi

    ew

    deco

    mpo

    sitio

    n an

    d as

    pect

    reu

    sabi

    lity.

    D

    emet

    erJ

    and

    DJ

    faci

    litat

    e th

    e st

    ruct

    ure-

    shy

    enca

    psul

    atio

    n of

    tra

    vers

    al-r

    elat

    ed

    beha

    vior

    al c

    once

    rns.

    JA

    sCo

    is a

    n as

    pect

    -orien

    ted

    prog

    ram

    min

    g la

    ngua

    ge t

    ailo

    red

    for

    com

    pone

    nt b

    ased

    so

    ftw

    are

    deve

    lopm

    ent.

    JM

    ang

    ler

    is a

    fra

    mew

    ork

    for

    load

    -tim

    e tr

    ansf

    orm

    atio

    n of

    Jav

    a pr

    ogra

    ms,

    whi

    ch

    supp

    orts

    con

    flict

    -fre

    e co

    mpo

    sitio

    n of

    inde

    pend

    ently

    dev

    elop

    ed a

    spec

    ts

    (im

    plem

    ente

    d as

    JM

    angl

    er t

    rans

    form

    er c

    ompo

    nent

    s) a

    nd t

    heir joi

    nt a

    pplic

    atio

    n to

    ex

    istin

    g ba

    se c

    lass

    es.

    Mix

    Juic

    e is

    an

    exte

    nsio

    n to

    Jav

    a, b

    ased

    on

    the

    differ

    ence

    -bas

    ed m

    odul

    e m

    echa

    nism

    .

    CBSE

    , © P

    rof. U

    we A

    ßman

    n 62

    44.4

    AO

    SD

  • Prof.

    U. A

    ßman

    n, CB

    SE

    63

    Prob

    lem

    of A

    OSD

    : Wea

    ver P

    rolif

    erat

    ion

    • W

    ho b

    uild

    s al

    l the

    se w

    eave

    rs, p

    oint

    cut s

    peci

    ficat

    ion

    lang

    uage

    s,

    exte

    nsio

    n en

    gine

    s, a

    nd te

    mpl

    ate

    expa

    nder

    s?

    • A

    nsw

    er:

    – U

    nive

    rsal

    poi

    ntcu

    t lan

    guag

    es

    – U

    nive

    rsal

    com

    posa

    bilit

    y ad

    d-on

    s

    Prof.

    U. A

    ßman

    n, CB

    SE

    64

    Uni

    vers

    al P

    oint

    cut L

    angu

    ages

    • Th

    e sp

    ecifi

    catio

    n of

    a p

    oint

    cut i

    s a

    grap

    h-th

    eore

    tic p

    robl

    em, a

    nd

    does

    not

    rely

    on

    the

    core

    nor

    asp

    ect l

    angu

    age

    • W

    eave

    r pro

    lifer

    atio

    n ca

    n be

    avo

    ided

    by

    univ

    ersa

    l poi

    ntcu

    t la

    ngua

    ges

    for s

    peci

    fyin

    g cr

    ossc

    ut g

    raph

    s th

    at in

    terc

    onne

    ct b

    ase

    and

    aspe

    ct in

    any

    lang

    uage

    Cor

    e A

    spec

    t

    Cro

    sscu

    t gr

    aph

    Poi

    ntcu

    t sp

    ecifi

    catio

    n

  • Prof.

    U. A

    ßman

    n, CB

    SE

    65

    Uni

    vers

    al P

    oint

    cut L

    angu

    ages

    • A

    poi

    ntcu

    t lan

    guag

    e co

    nnec

    ts n

    ames

    of t

    he c

    ore

    and

    the

    aspe

    ct

    – do

    es n

    ot k

    now

    mor

    e co

    ncep

    ts

    • It

    can

    be u

    sed

    univ

    ersa

    lly

    • 

    Exa

    mpl

    e:

    – X

    path

    , can

    it b

    e us

    ed a

    s po

    intc

    ut la

    ngua

    ge?

    – C

    an y

    ou s

    epar

    ate

    poin

    tcut

    s fro

    m A

    spec

    t/J a

    dvic

    es a

    nd a

    ddre

    ss a

    dvic

    e jo

    inpo

    ints

    ? – 

    Rel

    atio

    nal a

    lgeb

    ra, S

    QL,

    Dat

    alog

    – 

    Gra

    ph re

    writ

    ing

    – Lo

    gic

    Prof.

    U. A

    ßman

    n, CB

    SE

    66

    Tow

    ards

    Asp

    ect-O

    rient

    ed S

    yste

    m

    Dev

    elop

    men

    t (A

    OSD

    )

    ► 

    Asp

    ects

    are

    impo

    rtant

    in th

    e w

    hole

    life

    cycl

    e ■ 

    requ

    irem

    ents

    (ear

    ly a

    spec

    ts)

    ■ an

    alys

    is

    ■ de

    sign

    (mod

    el a

    spec

    ts)

    ■ im

    plem

    enta

    tion

    (cod

    e as

    pect

    s)

    ■ te

    st

    ► 

    Asp

    ect-a

    war

    e de

    velo

    pmen

    t use

    s cr

    ossc

    ut g

    raph

    s an

    d th

    eir

    spec

    ifica

    tion

    lang

    uage

    s fo

    r all

    lang

    uage

    s (m

    odel

    ing

    and

    prog

    ram

    min

    g)

    ► 

    [Joh

    anne

    s] s

    how

    s ho

    w to

    mak

    e cr

    ossc

    ut g

    raph

    s fo

    r arb

    itrar

    y la

    ngua

    ges

    ► 

    Asp

    ect-a

    war

    e to

    ols

    inte

    rpre

    t cro

    sscu

    t gra

    phs

    ► 

    Reu

    sew

    are

    is a

    met

    awea

    ver,

    a ge

    nera

    tor f

    or w

    eave

    rs

  • Prof.

    U. A

    ßman

    n, CB

    SE

    67

    44.5

    Eva

    luat

    ion:

    A

    spec

    ts a

    s C

    ompo

    sitio

    n Sy

    stem

    Component model

    Composition technique

    Composition language

    Sour

    ce co

    mpon

    ents

    (core

    , asp

    ect)

    Advic

    es us

    e fra

    gmen

    t com

    pone

    nts

    Grey

    box c

    ompo

    nents

    (asp

    ects

    with

    advic

    es

    and i

    ntrod

    uctio

    ns)

    Simp

    le se

    t of c

    ompo

    sition

    oper

    ators

    Asym

    metric

    comp

    ositio

    n (ex

    tensio

    n)

    Cros

    scut

    grap

    h defi

    nition

    s (wi

    th po

    intcu

    ts)

    Expr

    essio

    n-ba

    sed

    Prof.

    U. A

    ßman

    n, CB

    SE

    68

    The

    End

    ► 

    Man

    y sl

    ides

    cou

    rtesy

    to W

    im V

    ande

    rper

    ren,

    Vrij

    e U

    nive

    rsite

    t Bru

    ssel

    , an

    d th

    e A

    spec

    t/J te

    am