270 likes | 282 Views
Explore the Aspect-Oriented Programming (AOP) model in Ada95, focusing on Separation of Concerns (SoC) and Crosscutting Concerns. Learn about benefits, symptoms, AOP versioning, AspectJ, and AspectAda proposals for Ada95 extension.
E N D
Computer Science & Software Engineering AspectAda Aspect-Oriented Programming for Ada95 WORLD CLASS – through people, technology and dedication
Agenda • Separation of Concerns + Crosscutting • Aspect-Oriented Programming (AOP) Model • Logging Example • AspectAda Prototype Architecture • Effect on SW Quality
Separation of Concerns (SoC) • “Separation of Concerns (SoC)” (Parnas, Dijkstra): • realization of problem domain concepts into separate units of software. • Benefits of SoC • Better analysis and understanding of systems • Easy adaptability, maintainability and high degree of reusability. • Low Coupling/High Cohesion • SoC Fundamental to SW Development • Ada95 SoC • Packages, Subprograms, • Tagged Types, Protected Types, Tasks
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
Initial Picture of Crosscutting [Constantinides]
CORBA Servant Implementation procedure Do_Some(Self: inout Object; Data : in Data_t) is begin Tracer.Enter(Self.TraceId, “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.TraceId, “Do_Some”); exception when event :others => Mutex.Unlock(Self.Lock); Error_Logger.Log_Error(event, “Unknown Exception in Do_Some”); end Do_Some;
Crosscutting identification procedure Do_Some(Self: inout Object; Data : in Data_t) is begin Tracer.Enter(Self.TraceId, “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.TraceId, “Do_Some”); exception when event :others => Mutex.Unlock(Self.Lock); Error_Logger.Log_Error(event, “Unknown Exception in Do_Some”); end Do_Some;
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
AOP Version procedure Do_Some(Self: inout 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
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 • AspectJ – Dominant AOP language extension for Java • AspectAda – Our Proposal to extend Ada95 • Influenced by AspectJ
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: inout M_Object; Data : in Data_t) is ... begin ... end Do_Some;
Pointcuts • Set of joinpoints (object declaration) • Pointcut expression (AspectJ 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_* (inout M_Object; ..) or execution Some_Pk.Set_* (in out M_Object; ..);
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 : inout Mutex_Aspect) is begin Mutex_A.Mutex.Lock; Proceed; Mutex_A.Mutex.Unlock; whenothers => Mutex_A.Mutex.Unlock; raise; end Around;
Aspect Composition rules Generic Aspect Ada95 Modules • 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;
AOP Tracing Example: Aspect Spec with AspectAda; 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;
AOP Tracing Example: Aspect Body with Ada.Text_IO; use Ada.Text_IO; with Aspect_Ada; use Aspect_Ada; aspectbody Tracer is advice Before(Tracer : in Tracer_Aspect) isbegin 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;
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;
AspectAda Architecture: Conceptual View [Hofmeister Notation]
Weaver Prototype: Modular View Controller Selection Merging ASIS JoinPointModel Aspect Parser Pointcut Parser • ASIS Based (Ada95) • AdaGOOP (Aspects, Pointcuts) • Ada.Containers • Easy to adapt to Ada2005
Effects on SW Quality • Cohesion • One concern in Ada95 module • Crosscutting concerns modularized in aspects • Coupling • Minimal coupling modeled using pointcut expressions • Reversed dependency direction • Adaptability • Code comprehensibility • Tradeoff • Traceability
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
Conclusion • Crosscutting concerns • Joinpoint model (joinpoints, pointcuts, advices, aspects) • Tracing using AspectAda • AspectAda Prototype Architecture • Effects on SW Quality • Future Work
End www.cs.concordia.ca/~cc/research knuthp@gmail.com WORLD CLASS – through people, technology and dedication