aspect-oriented analysis and design - bcs.org · aspect-oriented analysis and design the theme...

28
Aspect-Oriented Analysis and Design The Theme Approach Siobhán Clarke Trinity College Dublin BCS Advanced Programming SIG, 11 th May 2006

Upload: dinhkien

Post on 15-Jul-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Aspect-Oriented Analysis and Design

The Theme Approach

Siobhán ClarkeTrinity College Dublin

BCS Advanced Programming SIG, 11th May 2006

Aspect-Oriented Analysis and Design with Theme 2

What’s wrong with objects – 1?

Concerns that crosscut multiple parts of a system cannot be modularized

Aspect-Oriented Analysis and Design with Theme 3

What’s wrong with objects – 2?

Class modularization encapsulates multiple concerns

Aspect-Oriented Analysis and Design with Theme 4

The Theme Approach

Brief History Lesson!

- Early ’90’s: Subject-Oriented Programming- Symmetric view of decomposition

- 1997+ Subject-Oriented Design- 2001: Subject-Oriented Design -> Theme/UML- 2003+ The Theme Process:

- Theme/UML – design- Theme/Doc – requirements analysis

Aspect-Oriented Analysis and Design with Theme 5

Overview

Theme/Doc for analysis

Theme/UML for design

View relationships between concerns

Model concernsseparately

Aspect-Oriented Analysis and Design with Theme 6

Theme/Docfind the themes – select potential concerns from text

A new game will randomly distribute crystals around the game worldIf players do not reach their initial location in time, they lose one energy point

R18

Dropped crystals will be re-scattered throughout the game areaPlayers lose energy at two units per five minute period in a game locationIf a player enters a location that has no players or characters in it, they may pick up any crystals or magical items thereWhen a game starts, players gain 10 units of energyEnergy is gained by two units when a player picks up a crystal entering a locationWhen two players meet on entering a location, they perform a duel of rock paper scissorsWhen a player completes a physical test challenge successfully they gain three units of energy and win a crystal

R21

R37R38

R40R42

R61

R80

R35

Aspect-Oriented Analysis and Design with Theme 7

Theme/Docfind the themes – select potential concerns from text

A new game will randomly distribute crystals around the game worldIf players do not reach their initial location in time, they loseone energy point

R18

Dropped crystals will be re-scattered throughout the game areaPlayers lose energy at two units per five minute period in a game locationIf a player enters a location that has no players or characters in it, they may pick up any crystals or magical items thereWhen a game starts, players gain 10 units of energyEnergy is gained by two units when a player picks up a crystal entering a locationWhen two players meet on entering a location, they perform a duel of rock paper scissorsWhen a player completes a physical test challenge successfully they gainthree units of energy and win a crystal

R21

R37R38

R40R42

R61

R80

R35

Aspect-Oriented Analysis and Design with Theme 8

Theme/Docgraphing the relationships between the concerns

concern

requirement

legend

Aspect-Oriented Analysis and Design with Theme 9

Theme/Doca look forward to the final goal

basethemes

enter-location

R38 R61

start

R18 R15

R24

R32

R98

crosscuttingthemes (aspects)

TrackEnergy

R80 R77

R42

R40

R37

R21

R41

duel

R31 R52

R16

R67

R75

Aspect-Oriented Analysis and Design with Theme 10

Theme/Docgraphing the relationships between the concerns

concern

requirement

legend

Aspect-Oriented Analysis and Design with Theme 11

Theme/Docgetting there.. aspects (probably from shared requirements)

enter-location

R38 R61

TrackEnergy

R80 R77

R21

R40

R37

R41

R42 Energy is gained by two units when a player picks up a crystal entering a location

R38 If a player enters a location that has no players or characters in it, they may pick up any crystals or magical items there

Aspect-Oriented Analysis and Design with Theme 12

Theme/Docgetting there.. base themes

enter-location

R38 R61

start

R14 R15

R24

R32

R98

duel

R35 R52

R16

R67

R75

Theme too general? split into smaller ones

Themes too similar?unify synonyms, group

Theme not really useful?delete it!

Requirement “orphaned”?find a home

Requirement ambiguous?resolve and refine

Aspect-Oriented Analysis and Design with Theme 13

Theme/UMLtheme design process

Aspect-Oriented Analysis and Design with Theme 14

Theme/UMLmodel themes separately – base themes with standard UML

«theme»Start

GameAdmin

+ newGame(String, int)

Location

+ name+ northEast : Coordinate+ northWest : Coordinate+ southEast : Coordinate+ southWest : Coordinate

Vector

gameWorld

gameLocations 1

1..*

Game

+ setGameLocations(Vector)+ setThroneRoom(Location)

gameLocations

1

throneRoom

1

Player

+ getLocation()+ setGame()

currentLocation

1

activeGames

0..*

players

0..*

1

- gameDuration : int- name : String

- name : String- IPAddress : String

«theme»EnterLocation

Player

+ setLocation()+ checkOtherPlayers()+ takeCrystals()+ incrementCrystals()+ takeMagicItems()+ setMagicItem()

Location

+ takeCrystals()+ takeMagicItems()GPSComponent

+ getCurrentGPSLocation()

signalsnewLocation()duel()

Game

+ inGameLocation()+ getOtherPlayers()

signalsleave(Player)

1..*

players

game

1- crystals : int

- crystals : int

MagicItem

0..* 0..*

Aspect-Oriented Analysis and Design with Theme 15

«theme»track-energy < Energy.moveLocation(..) >

< Energy.energyAction(..) >< Energy.joinGame(..) >

Theme/UMLmodel themes separately – aspect themes with minor UML extensions

Template parameters used to reason about triggers of behaviour in aspect theme- grouped by behaviour sequence within < > brackets

Aspect-Oriented Analysis and Design with Theme 16

Crosscutting behaviorspecified to happenafter real behavior

Execution of real behavior

isPlayerInLocation()

_do_moveLocation(..)

setChangeAmount(2)

setChangeAmount(1)

:Game

inLocation

:Energy

moveLocation(..)

sd moveLocation

alt[inLocation=true]

[inLocation=false]

Theme/UMLmodel themes separately – aspect themes with minor UML extensions

Distinguish between:- execution of base operation (_do_op()) and

- execution of crosscuttingbehaviour (op())

Aspect-Oriented Analysis and Design with Theme 17

Theme/UMLmodel themes separately – aspect triggers with control flow restrictions

after()

_do_op1(..)

:Class2:Class1

op1(..)

sd restrictedTrigger

op2(..)

before()

_do_op2(..)

op2() a triggeronly

within this control flow

control flow of _do_op1()

Aspect-Oriented Analysis and Design with Theme 18

Theme/UMLmodel themes separately – aspect themes arising from detailed design

«active»GamesAdmin

- marshallActiveGames()- unmarshallActiveGames()

signalscheckGamesAvailable()CrystalGamesAvailable(String)

activeGames

0..*

«active»Game

+ getName()+ marshallGame()+ unMarshallGame()+ unMarshallLocation()+ unMarshallPlayer()

TPlayer

+ pStateChange(..)- _do_pStateChange(..)+ joinGame(..)- _do_joinGame(..)

TLocation

+ lStateChange(..)- _do_lStateChange(..)

LocationUpdate(String)PlayerUpdate(String)FullGameStateRequest(String)FullGameState(String)

signals

locations1..*

game

1..*

players 1..*

game1

«theme»P2PCommunication

<TPlayer.joinGame(..)><TPlayer.pStateChange(..)><TLocation.lStateChange(..)><TGamesAdmin.newGameAdmin(..)>

Location

+ marshallState()+ update(String)

Player

+ marshallState()+ update(String)

TGamesAdmin

+ newGameAdmin()_do_newGameAdmin()+ start()

alt

alt

:Game

unMarshallLocation(locInfo)

:Game

LocationUpdate(locInfo)

update(String)

:Location

_do_pStateChange(..)

marshallState()

game:Gamep:TPlayer

pStateChange(..)

playerInfo

getName()

:Game

PlayerUpdate(playerInfo)

_do_lStateChange(..)

marshallState()

game:Gamel:TLocation

lStateChange(..)

locationInfo

getName()

LocationUpdate(locationInfo)

unMarshallPlayer(pInfo)

:Game

PlayerUpdate(pInfo)

update(String)

:Player

«theme»P2PCommunication

<TPlayer.joinGame(..)><TPlayer.pStateChange(..)><TLocation.lStateChange(..)><TGamesAdmin.newGameAdmin(..)>

sd lStateChange

sd pStateChange

sd LocationUpdate

sd PlayerUpdate

[gameName=this.name]

[gameName=this.name]

Aspect-Oriented Analysis and Design with Theme 19

Theme/UMLtheme composition process

Aspect-Oriented Analysis and Design with Theme 20

«theme»

Start

match[name]

«theme»EnterLocation

«theme»Duel

Theme/UMLcompose themes – Composition Relationship and base themes

composition relationship:- merge

Player

duel()

Player

signalsinitiateDuel()magicSelected(MagicItem)wagerTwoCrystals()wagerMagicItem(MagicItem)wagerTwoMagicItems(..)wagerCrystal()wagerAccepted()duelRevealRPS(Player, String)

+ getMagicItems()- duelLoser()+ addCrystals(int)+ decrementCrystals(int)+ addMagicItem(MagicItem)+ deleteMagicItem(MagicItem)- updateRPS()

- crystalsOffered : Boolean- crystals : int- wagerAccepted : Boolean- wagerAgreed : Boolean- finishedReceived : Boolean- rockPlayerScissors : String

signals

composition relationship:- override

Composition Relationship tags:- match[name]- nomatch- for conflict resolution

- [prec]- reconcil[explicit[ {..} ]]- reconcil[default[Type {..}]]

- ordering sequence for op merge

Aspect-Oriented Analysis and Design with Theme 21

«theme»track-energy

<Energy.moveLocation(..) ><Energy.energyAction(..)><Energy.joinGame(..)>

«theme»

game

bind[ < Player.setLocation() > < Player.{incrementCrystals(), addCrystals(),

completeWizardErrand(), completeWarriorTest() } > < Player.joinGame() > ]

Binding base design elements totemplate parameters.

Theme/UMLcompose themes – Composition Relationship and aspect themes

Aspect-Oriented Analysis and Design with Theme 22

Map to AspectJ«theme»

TrackEnergy<Energy.moveLocation(..) ><Energy.energyAction(..)><Energy.joinGame(..)>

bind[ < Player.setLocation() > < Player.{incrementCrystals(),

addCrystals(), completeWizardErrand(), completeWarriorTest() } >

< Player.joinGame() > ]

«theme»

GameEnergy

Game

:Type

templateOp()

crosscuttingOp()

_do_templateOp()

Abstract Aspect

Concrete Aspect

IntertypeDeclarations Pointcuts

Advice

ConcreteIntertype

Declarations

ConcretePointcuts

Aspect-Oriented Analysis and Design with Theme 23

Small flavour – concrete aspect

public aspect ConcreteTrackEnergy extends TrackEnergy {declare parents: Player implements EnergyEntityI;declare parents: Game implements GameI;

pointcut moveLocation(EnergyEntityI energyEntity): this(energyEntity) &&execution (* Player.setLocation(..));

pointcut energyAction(EnergyEntityI energyEntity):this(energyEntity) &&(execution (* Player.incrementCrystals(..)) ||execution (* Player.addCrystals(..)) || execution (* Player.completeWarriorTest(..)) ||execution (* Player.completeWizardErrand(..)));

pointcut joinGame(Player player):this(player) && execution (* Player.joinGame(..));

}

Aspect-Oriented Analysis and Design with Theme 24

Map to CME - aspects«theme»

TrackEnergy<Energy.moveLocation(..) ><Energy.energyAction(..)><Energy.joinGame(..)>

bind[ < Player.setLocation() > < Player.{incrementCrystals(),

addCrystals(), completeWizardErrand(), completeWarriorTest() } >

< Player.joinGame() > ]

«theme»

GameEnergy

Game

:Type

templateOp()

crosscuttingOp()

_do_templateOp()

Compose-game.hl

extend concern Game with TrackEnergyTheme;

extend typeBaseTheme: Player

withTrackEnergyTheme: Energy;

advise methodBaseTheme:Player.setLocation(Location)

with after::TrackEnergyTheme: Energy.setChangeAmount();

...

Track Energy Theme Package Game Theme Package

Aspect-Oriented Analysis and Design with Theme 25

Map to CME – baseStart Theme Package

Player.javapublic class Player { ... }

Location.javapublic class Location { … }

GameAdmin.javapublic class GameAdmin { … }

Game.javapublic class Game { … }

«theme»

Start

«theme»Duel

«theme»EnterLocation

ThemeName[“Game”]match[name]

Player

duel()signals

Player

duel()signals

Enter Location Theme Package

MagicItem.javapublic class MagicItem { … }

Player.javapublic class Player {

... public void duel(Player p) {

// stub }}

...

Location.javapublic class Location { … }

Game.javapublic class Game { … }

MagicItem.javapublic class MagicItem { … }

Player.javapublic class Player {

... public void duel(Player p) {

… }}

Wager.javapublic class Wager { … }

...CME Composition Specification

Compose-game.hl

merge concerns StartTheme, EnterLocationTheme,

DuelTheme => Game;

override method EnterLocationTheme: Player.duel(Player)with DuelTheme: Player.duel(Player);

Aspect-Oriented Analysis and Design with Theme 26

Theme publicationsSiobhán Clarke, Robert J. Walker. "Generic Aspect-Oriented Design with Theme/UML“ In Aspect-Oriented Software Development, Addison-Wesley, 2005

Elisa L.A. Baniassad, Siobhán Clarke. "Theme: An Approach for Aspect-Oriented Analysis and Design"In Proceedings of the 26th International Conference on Software Engineering (ICSE), Edinburgh, 2004.

Siobhán Clarke. "Extending standard UML with model composition semantics" in Science of Computer Programming, Volume 44, Issue 1, pp. 71-100. Elsevier Science, July 2002.

Siobhán Clarke, Robert J. Walker. "Towards a Standard Design Language for AOSD" In Proceedings of the 1st International Conference on Aspect-Oriented Software Development (AOSD), Enschede, The Netherlands, April 2002.

Siobhán Clarke, Robert J. Walker. "Composition Patterns: An Approach to Designing Reusable Aspects" In Proceedings of the 23rd International Conference on Software Engineering (ICSE), Toronto, Canada, May 2001.

Siobhán Clarke. "Composition of Object-Oriented Software Design Models“ Ph.D. Thesis, January 2001, Dublin City University.

Siobhán Clarke. "Composing Design Models: An extension to the UML" In Proceedings of the Third International Conference on the Unified Modeling Language (UML), UK, 2000. Volume 1939, LNCS

Siobhán Clarke, William Harrison, Harold Ossher, Peri Tarr. "Subject-Oriented Design: Towards Improved Alignment of Requirements, Design and Code" In Proceedings of Object-Oriented Programming, Systems, Languages and Applications (OOPSLA) Denver, Colorado U.S., 1999.

Aspect-Oriented Analysis and Design with Theme 27

… and a plug!

Aspect-Oriented Analysis and Design with Theme 28

Questions…