Modeling Aspects by Category Theory Serge P. Kovalyov Novosibirsk, Russia FOAL 2010 Aspect-oriented software development Mission: explicit separation and composition of concerns Motivation Concerns are tangled Concerns crosscut modular architecture bounds Traceability is compromised (ability to determine what each fragment of the system is included into it for) Proposed solution Equip program models with traces of refinements that produce them from concerns (i.e. “label” programs by concerns) Explicitly identify, compose (weave), and separate concerns Application: enhance modular design technologies with aspect handling capabilities FOAL 2010 Category-theoretic formalization Explicit definition of intuitive notions Describing objects via relations with similar objects Universality (existence and uniqueness of connection with similar objects) Naturality (independence of the result on the way it is reached) Formal specification and verification of systemic properties Avoiding appeal to “interiors” of objects Constructing object by systemic criteria Objects (things) Morphisms (connections) Functors (translations) Complexity Modularity Traceability FOAL 2010 Category of descriptions Category c-DESC Example: category of UML classes and inheritance relations Scenario modeling Objects are formal models of programs (descriptions) Morphisms are actions of integrating components into systems Composition is multistep integration Identity morphisms are “doing nothing” Category Pos Objects are partially ordered sets (posets) of events ordered by causal dependence Morphisms are poset homomorpisms (preserving events and ordering) FOAL 2010 Diagrams c-DESC-diagram Functor : X c-DESC Graph of X labeled by c-DESC-objects and c-DESC-morphisms Cocone Natural transformation of a diagram (base) to a singleton (vertex) Colimit of a diagram Universal cocone with base Minimal “container” that encapsulates objects of respecting their interconnections FOAL 2010 Configurations Well-formed configuration Is a c-DESC-diagram (of components and their interconnections) Has a colimit (system built from interconnected components) Satisfies structural constraints Configurations of scenarios Well-formed configurations are disjoint unions of cocones Examples well-formed: parallelism FOAL 2010 ill-formed: concurrency Interfaces Category SIG of interfaces and their integration actions Functor sig : c-DESC SIG Default realization of any interface Functor sig* : SIG c-DESC sig ◦ sig* = 1SIG Bijective map Mor(sig*(I), A) to Mor(I, sig(A)) by functor sig (i.e. sig* is left adjoint to sig with identity as the unit) Example: signature of a program module Scenario interface Set of events Forgetful functor |–| : Pos Set |–| FOAL 2010 Refinements Category r-DESC Objects are models Morphisms are refinements (individual component development steps) Examples Elaborating requirements Implementing specification by means of a programming language Scenario refinement Replacing atomic events with subscenarios fully inheriting the order Dual to a surjective homomorphism FOAL 2010 Traceable refinements Tracing a refinement r : X S Labeling S by concerns that constitute X Trace is a c-DESC-morphism t : S X dual to a refinement sig(t) has right inverse (to preserve traceability at subsequent integrating S into a larger system) r X S t = rop sig s : sig(t) ◦ s = 1 sig(X) sig(S) sig(t) Every refinement of scenarios is traceable FOAL 2010 Enhancing descriptions with aspects Aspect-oriented description is a pair A, l : sig(A) L A Ob c-DESC is a “modular” part L Ob SIG is an aspect structure l labels sig(A) by aspects (sig(l) is a trace) Morphism of AO-description A, l to A', l' is a pair p, q A, l : sig(A) L p sig(p) q A', l' : sig(B) L' Aspect-oriented scenarios Object are pomsets (labeled posets) Morphisms are homomorphisms that preserve labeling FOAL 2010 Aspect-oriented design AO-configurations are modular configurations that admit any labeling of components by aspects (i.e. have suitable colimit) Interfaces of AO-descriptions mod : A, l | A (modular design interfaces) asp : A, l | l (aspect design interfaces) int : A, l | sig(A) (original interfaces) AO-refinements are duals to such AO-morphisms that are produced from traces Aspect-oriented scenario modeling Configurations are disjoint unions of AO-cocones Functor mod forgets labeling Functor mod* labels each event by a unique label (event itself) Refinement replaces events with subscenarios fully inheriting the order and detailing the labeling FOAL 2010 Aspects Aspects are “elementary” building blocks of AO-descriptions An integration of an aspect into a system is an invertible embedding at the level of aspect structures A is an aspect iff for every object A' and morphism p, q : A A' q has left inverse (often a trace) Aspects in scenario modeling Aspect is a scenario with all events labeled by the same label Aspect is precisely a pair A, ! : |A| 1 FOAL 2010 Weaving Specifying how to weave an advice W with a base program B Connector: C Pointcut descriptor: j : C B Entry points descriptor: e : C W Performing weaving Pushout (colimit): 1C, e : C C W j B X Weaving labeled scenarios Weaving exists if a connector “tolerates” concurrency (i.e. it doesn’t impose specific order of executing different aspects of the advice bound to the same join point ) Weaving with an aspect preserves labeling of a base FOAL 2010 Explication of aspect structure Explication of aspect structure of an AO-description A, l Obtaining “actual” refinement from concerns r-DESC-morphism s : X A where sop is a trace and sig(sop) = l An explication of A, l is universal if every AO-morphism p, q : A, l A', l' has an explication (provided that A', l' has) p : A A' sop rop p' : X X ' Explicating labeled scenarios Every explication is universal Every aspect is explicable “Many” scenarios are inexplicable e.g. interleaving FOAL 2010 Separation of concerns Subaspect of an AO-description S AO-morphism m : A S where A is an explicable aspect Explication m' of m is right inverse to a trace Explication diagram of m is a pullback (i.e. mod(m) is a “preimage” of m' along an explication trace of S) An aspect has no proper subaspects If S is an aspect, then m is an isomorphism Each explicable labeled scenario can be partitioned to subaspects Each scenario can be labeled by linearly ordered subaspects Maximal partition: assign a unique label to each event (i.e. apply mod*) Minimal partition: factorize by linear equicomparability relation FOAL 2010 Industrial application Distributed measurement system (DMS) development Main measurement cycle is linear order of separable aspects Measurement automation infrastructure aspects are woven to it undermining separation of concerns DMS scenario weaving schema measure store validate compute display + metadata model + monitoring + security FOAL 2010 Summary Understanding systemic nature of AOSD concepts Providing formal paradigm-neutral description of Aspects Weaving Explication of aspect structure Separation of concerns Verifying structural properties of aspect-oriented operations Applying in concurrency theory: labels are aspects Applying in industry: large-scale DMS development FOAL 2010 Thank you for your attention FOAL 2010