Appendix A. Modeling Aspects and Use-Case Slices in UML

This appendix provides a quick guide to notation for modeling aspects as used in this book. Let’s recount the principles we use to model aspects. We treat aspect as part of an overlay (i.e., use-case slice) that is placed on top of an existing class or a set of classes. The names of the classes and operations must match those in the element structure before proper overlaying can take place. The use-case slice is a larger concept of an overlay than aspects. Whereas aspects can only add to existing classes, use-case slices can add entire new classes as well. Moreover, whereas parameterization of pointcuts is for binding existing locations (i.e., join points), use-case-slice template parameters allow you to define completely new elements. The key to understanding the notation is to know how overlaying is achieved.

Modeling Intertype Declarations with Class Extensions

A class extension is a modular extension to an existing class. It defines the features (attributes, operations, and relationships) to be overlaid onto an existing class. The name of the class and the class extension must correspond. See Figure A-1.

Figure A-1. 

Overlay Semantics

The logging aspect adds:

  • an operation named extractData()

  • to the Room class.

AspectJ Mapping

This corresponds to an intertype declaration as listed below:

1. public aspect Logging {
2.     public void Room.extractData() {
3.     // code
4.     }
5. }

Modeling Advices with Operation Extensions

An operation is the behavioral response when an element is invoked. An operation extension is a modular extension to an operation. Since operations are defined within classes, operation extensions are also defined within class extensions. See Figure A-2.

Figure A-2. 

Overlay Semantics

The logging aspect adds:

  • an operation extension logData

  • to the ReserveRoomHandler class makeReservation() operation, that is, to the structural context,

  • before the execution point when a call is made to Room.retrieve(), that is, behavioral context.

AspectJ Mapping

This corresponds to an advice as follows:

1. public aspect Logging {
2.     before () :
3.         withincode (void ReserveRoomHandler.makeReservation())
4.	     && call (void Room.retrieve()) {
5.         // code
6.     }
7. }

Semantics of Before and After

Before and after operation extensions execute before or after existing execution points. Figure A-3 shows the use of before and after operation extensions.

Figure A-3. 

The figure contains two frames:

  • Frame shows the execution of operation extension logData1 before call to Room.retrieve().

  • Frame shows the execution of operation extension logData2 after call to Room.retrieve().

Semantics of Around

Around operation extensions wrap up existing codes and determine if existing code can proceed. Figure A-4 shows how operation extensions execute around existing execution points.

Figure A-4. 

The figure contains two frames:

  • Frame shows the execution of operation extension checkAuthorization around call 〈Control〉.performRequest().

  • Frame shows the continuation of call to 〈Control〉.performRequest() when checkAuthorization initiates proceed.

Modeling Pointcuts

A pointcut gives the context in which an operation extension executes a name. This context can comprise structural context, behavioral context, or both. See Figure A-5.

Figure A-5. 

Overlay Semantics

The logging aspect adds:

  • an operation extension logData

  • to an existing operation within the ReserveRoomHandler class (This is parameterized as 〈roomAccessOp〉, and it establishes the structural context of the operation extension.)

  • before a call to a Room operation (This is parameterized as 〈roomCall〉 and it establishes the behavioral context of the operation extension.)

AspectJ Mapping

This corresponds to pointcuts as follows:

1. public aspect Logging {
2.    pointcut roomAccessOp()
3.             : withincode (void ReserveRoomHandler.*(..)) ;
4.    pointcut roomCall()
5.             : call (void Room.*(..)) ;
6.
7.    before () : roomAccessOp() && roomCall() {
8.     // code
9.     }
10. }

Modeling Use-Case Slices

A use-case slice contains one collaboration, zero or more classes, and one or more aspects. The diagram in Figure A-6 depicts the various parts of a use-case slice.

Figure A-6. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.244.250