220 likes | 436 Views
AOP/cross-cutting. What is an aspect?. What is an aspect?. An aspect is a modular unit that cross-cuts other modular units. What means cross-cutting?
E N D
AOP/cross-cutting What is an aspect?
What is an aspect? • An aspect is a modular unit that cross-cuts other modular units. • What means cross-cutting? • Apply AOP to AOP. Tease an aspect apart into three units: ideal graph, labels on nodes and edges of ideal graph, application to concrete graph using connectors: specifies cross-cutting
What is an aspect? • An aspect is a modular unit that cross-cuts other modular units. • Example: MU 1: application code, MU 2: class library code. Application code uses names from class library. Cross-cutting. • MU 1 is an aspect! Not reasonable • What is missing?
What is an aspect? • An aspect is a modular unit that cross-cuts and enhances other modular units. • Previous example now ruled out. • Example: MU 1: APPC, MU 2: class graph. Cross-cutting is indirect through a connector. APPC is an aspect
Stand-alone = requiring context in order to function Alternative definition • An aspect • is a modular unit that has no stand-alone function and • that affects other modular units
Other definition (Xerox PARC) • Implement properties. Some are implemented by generalized procedures. Those that are not implemented by generalized procedures are called aspects. • Aspects are defined modulo programming language and a set of components
Terminology • Building block = BB • Participants (classes at basic level) = BB of type 1 • APPC = BB of type 2 = consisting of set of generic BB of type 1. • Connectors = map generic BB = implements cross-cutting
AOP • components = building blocks type 1 • whatever does not fit into one building block of type 1 is expressed as one building block type 2 that consists of a set of generic building blocks of type 1. • generic building blocks of a building block of type 2 are mapped to building blocks of type 1.
Generic BB • A building block with holes
AOP • Properties of mapping • one generic building block is mapped to one or more building blocks • building blocks may have parts. One part of generic building block is mapped to one or more parts of corresponding generic building block.
Example: APPCs • Ideal graph: participant graph • Labels on nodes and edges: participant code • Concrete graph: participant graph or application class graph • Connectors specify cross-cutting
Something missing in APPCs • Components, connectors • Components • provided, required interface • required interface includes participant graph • participant code • also needs help from other components that are connected to local participants
Improved APPCs • Components • provided, required interface • required interface includes participant graph • participant code • list of imported components • connectors
LoggingPricing Interface of Pricing becomes interface of LoggingPricing Logging Pricing Summing
CountingLocking Interface of Counting becomes interface of CountingLocking Locking Counting
Visitors and components? component Summing { participant Source { Target t; int sum() {cg.traverse(this, new Strategy(“from Source to Target”), new Visitor{ int sum s; start(){s=0;}; void before(Target host){ s+=host.what;} } } participant Target { public int what;} }
Example • Have component for Pricing • Want to log instance creation of three participant classes. Use Logging component and connect to three participants
Cross-cutting • Does not only mean inserting aspect code into enhanced unit. • There is interaction between aspect code and modified unit code. Some aspects can change structure of modified unit others just insert additional code into old structure
Theory of cross cutting • Model programs as graphs (e.g. class diagrams, abstract syntax trees, etc.) • Aspects: model as graph editing instructions modeled with respect to an ideal graph. • Graph editing: add new nodes and edges and add to node labels and edge labels
Specifying cross-cutting • Uniform: node to nodes, edge to edges: simple weaving • explicit: {A,B,C,D} • succinct: Nodes(Graph(“From A to D”)) • Non-uniform: edge to multiple edges: code is different from target edge to target edge
Specifying cross-cuttingmapping • With traversal. From A to B: B mapped to multiple targets • Without traversal. Two classes A and B with some connection? Without traversal is an uninteresting special case? Name map is the cross-cutting.
Use of traversal strategiesto specify cross-cutting in AOP • Set of classes: Nodes(strategy) • Graph refinement: map participant graph