Computer Science Software Engineering Aspect Ada AspectOriented Programming




![Initial Picture of Crosscutting [Constantinides] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 5 Initial Picture of Crosscutting [Constantinides] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 5](https://slidetodoc.com/presentation_image/9baa5c9174884618009d0254a34676d5/image-5.jpg)















![Aspect. Ada Architecture: Conceptual View [Hofmeister Notation] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 Aspect. Ada Architecture: Conceptual View [Hofmeister Notation] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003](https://slidetodoc.com/presentation_image/9baa5c9174884618009d0254a34676d5/image-21.jpg)






- Slides: 27

Computer Science & Software Engineering Aspect. Ada Aspect-Oriented Programming for Ada 95 WORLD CLASS – through people, technology and dedication KONGSBERG 9/29/2020 1

Agenda § Separation of Concerns + Crosscutting § Aspect-Oriented Programming (AOP) Model § Logging Example § Aspect. Ada Prototype Architecture § Effect on SW Quality KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 2

Separation of Concerns (So. C) § “Separation of Concerns (So. C)” (Parnas, Dijkstra): – realization of problem domain concepts into separate units of software. § Benefits of So. C – Better analysis and understanding of systems – Easy adaptability, maintainability and high degree of reusability. – Low Coupling/High Cohesion § So. C Fundamental to SW Development § Ada 95 So. C – Packages, Subprograms, – Tagged Types, Protected Types, Tasks KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 3

Crosscutting Concerns § Certain properties cannot be localized in single modular units, but their implementation cuts across the decomposition hierarchy of the system. – These properties are called crosscutting concerns, or aspects. § Concern (Requirement) – Functional – Non-functional – Design § Crosscutting Concern – A concern that is implemented in more than one location – security, logging, synchronization, fault tolerance, design by contract KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 4
![Initial Picture of Crosscutting Constantinides KONGSBERG 9292020 KONGSBERG 26 August 2003 5 Initial Picture of Crosscutting [Constantinides] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 5](https://slidetodoc.com/presentation_image/9baa5c9174884618009d0254a34676d5/image-5.jpg)
Initial Picture of Crosscutting [Constantinides] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 5

CORBA Servant Implementation procedure Do_Some(Self: in out Object; Data : in Data_t) is begin Tracer. Enter(Self. Trace. Id, “Do_Some”); Mutex. Lock(Self. Lock); . . -- Do business-logic --(Also invoking methods across CORBA). . Fault_Tolerance. Log_State(Make_Stream(Data)); Mutex. Unlock(Self. Lock); Tracer. Exit(Self. Trace. Id, “Do_Some”); exception when event : others => Mutex. Unlock(Self. Lock); Error_Logger. Log_Error(event, “Unknown Exception in Do_Some”); end Do_Some; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 6

Crosscutting identification procedure Do_Some(Self: in out Object; Data : in Data_t) is begin Tracer. Enter(Self. Trace. Id, “Do_Some”); Mutex. Lock(Self. Lock); . . -- Do business-logic --(Also invoking methods across CORBA). . Fault_Tolerance. Log_State(Make_Stream(Data)); Mutex. Unlock(Self. Lock); Tracer. Exit(Self. Trace. Id, “Do_Some”); exception when event : others => Mutex. Unlock(Self. Lock); Error_Logger. Log_Error(event, “Unknown Exception in Do_Some”); end Do_Some; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 7

Symptoms of Crosscutting § Crosscutting imposes two symptoms on software development: – Code scattering: implementation of some concerns not well modularized but cuts across the decomposition hierarchy of the system. – Code tangling: a module may contain implementation elements (code) for various concerns. § Problems – Low cohesion – Strong coupling – Low reusability, adaptability – Difficult comprehensibility KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 8

AOP Version procedure Do_Some(Self: in out Object; Data : in Data_t) is begin -- Do business-logic --(Also invoking methods across CORBA) end Do_Some; § Aspects – Tracer – Mutex – FT State – Exception handling § Composition rules – Rules for inserting aspect behavior to components KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 9

AOP Programming Model KONGSBERG 9/29/2020 10

Aspect Oriented Programming § AOP Complementary to OOP as OOP was to procedural programming § Also applicable to procedural programming § Aspect Languages extends traditional programming languages – Abstractions for representing crosscutting concerns (Aspects) – Composition of Aspects and traditional modules (Weaving) – Improves modularity, adaptability, traceability – Aspect. J – Dominant AOP language extension for Java § Aspect. Ada – Our Proposal to extend Ada 95 – Influenced by Aspect. J KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 11

Joinpoint § Well defined instant in the execution of a program – Subprogram execution – Finalization, Initialization, Adjust (Controlled Types) – Variable access (Object declarations) – Package body statement block – Named block statements – Named loop statements – Rendezvous/Entry points procedure Do_Some(Self: in out M_Object; Data : in Data_t) is. . . begin. . . end Do_Some; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 12

Pointcuts § Set of joinpoints (object declaration) § Pointcut expression (Aspect. J Influenced) § Primitive pointcuts – Call – Execution – Get/Set of variables § Wildcard matching (*, . . ) § Composition using and, or, xor, not § When a pointcut is matched, an advice can be executed My_PC : Pointcut : = execution Some_Pk. Do_* (in out M_Object; . . ) or execution Some_Pk. Set_* (in out M_Object; . . ); KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 13

Advice § Code module (as a subprogram) that attaches to a pointcut § Injects behavior at all joinpoints selected by that pointcut § Three types: – Before (code injected before the joinpoint) – After (code injected after the joinpoint) – Around (code injected around (in place of) code from joinpoint advice Around(Mutex_A : in out Mutex_Aspect) is begin Mutex_A. Mutex. Lock; Proceed; Mutex_A. Mutex. Unlock; when others => Mutex_A. Mutex. Unlock; raise; end Around; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 14

Aspect § A modular unit of crosscutting behavior – Advice type (tagged) - Simple (Performance) - Detailed (Contextual information) – Advice(s) bound to pointcut(s) (Advice clause) – Like a package can have subprograms, types. . . § Parameterized to bind to one or more pointcut(s) generic Mutex_P : Pointcut; aspect Mutex_Aspects is type Mutex_Aspect is new Simple_Aspect with record Mutex : Mutex_t; end Mutex_Aspect; advice Around. . . for Around’Advice use Mutex_P; end Mutex_Aspects; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 Composition rules Generic Aspect Ada 95 Modules 15

Logging Example KONGSBERG 9/29/2020 16

AOP Tracing Example: Aspect Spec with Aspect. Ada; generic Tracer_P : Pointcut; aspect Tracer is type Tracer_Aspect is new Aspect_Ada. Detailed_Aspect with null record; advice Before(Tracer : in Tracer_Aspect); for Before’Pointcut use Tracer_P; advice After(Tracer : in Tracer_Aspect); for After’Pointcut use Tracer_P; end Tracer; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 17

AOP Tracing Example: Aspect Body with Ada. Text_IO; use Ada. Text_IO; with Aspect_Ada; use Aspect_Ada; aspect body Tracer is advice Before(Tracer : in Tracer_Aspect) is begin Put_Line(“==> “ & Image(Get_Join_Point(Tracer). all)); end Before; advice After(Tracer : in Tracer_Aspect) is begin Put_Line(“<==” & Image(Get_Join_Point(Tracer). all)); end After; end Tracer; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 18

AOP Tracing Example: Composition Rules with Tracer; use Tracer; weaver CMS_Proto is Gun_Control_All_PC : Pointcut : = execution Gun*. *(. . ); aspect Gun_Control_Logger is new Tracer_Aspect(Tracer_P => Gun_All_PC); end CMS_Proto; KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 19

Aspect. Ada Prototype Architecture KONGSBERG 9/29/2020 20
![Aspect Ada Architecture Conceptual View Hofmeister Notation KONGSBERG 9292020 KONGSBERG 26 August 2003 Aspect. Ada Architecture: Conceptual View [Hofmeister Notation] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003](https://slidetodoc.com/presentation_image/9baa5c9174884618009d0254a34676d5/image-21.jpg)
Aspect. Ada Architecture: Conceptual View [Hofmeister Notation] KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 21

Weaver Prototype: Modular View Controller Selection Merging ASIS Join. Point. Model Aspect Parser KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 § ASIS Based (Ada 95) § Ada. GOOP (Aspects, Pointcuts) § Ada. Containers § Easy to adapt to Ada 2005 Pointcut Parser 22

Effects on SW Quality KONGSBERG 9/29/2020 23

Effects on SW Quality § Cohesion – One concern in Ada 95 module – Crosscutting concerns modularized in aspects § Coupling – Minimal coupling modeled using pointcut expressions – Reversed dependency direction § Adaptability § Code comprehensibility – Tradeoff § Traceability KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 24

Future Work § Extended joinpoint model – Call, Set/Get – Named blocks, named loops – Export of context at Joinpoints (objects, arguments) § Extend GPS Plugin (GNAT Programming System) § Joinpoint model and Ada generics § Increased Aspect reusability § Design by contract support § Open for suggestions KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 25

Conclusion § Crosscutting concerns § Joinpoint model (joinpoints, pointcuts, advices, aspects) § Tracing using Aspect. Ada § Aspect. Ada Prototype Architecture § Effects on SW Quality § Future Work KONGSBERG 9/29/2020 © KONGSBERG 26 August 2003 26

End www. cs. concordia. ca/~cc/research knuthp@gmail. com WORLD CLASS – through people, technology and dedication KONGSBERG 9/29/2020 27