Generic Programming using Adaptive and Aspect-Oriented Programming

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Introduction To System Analysis and Design
THE OBJECT-ORIENTED DESIGN WORKFLOW Interfaces & Subsystems.
(C) 1998 Tendril Software Inc. StructureBuilder Tendril Software Inc. OOPSLA ‘98 Demo Neeraj Sangal, President Tendril Software Karl.
1. 2 IBM connections for ingredients to adaptive plug-and-play components (APPCs) Adaptive Programming developed with support from IBM: Cun Xiao, Ignacio.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 09. Review Introduction to architectural styles Distributed architectures – Client Server Architecture – Multi-tier.
Introduction To System Analysis and Design
Odyssey A Reuse Environment based on Domain Models Prepared By: Mahmud Gabareen Eliad Cohen.
Slides for Gregor Kiczales Two versions –short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) –long version: Controlling.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Drawbacks of object-oriented software development Lecture P12 T120B pavasario sem.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Adaptive Software Kevin Cella Graduate Seminar 02/04/2005.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Review of Parnas’ Criteria for Decomposing Systems into Modules Zheng Wang, Yuan Zhang Michigan State University 04/19/2002.
Advanced Software Development Karl Lieberherr CSG 260 Fall Semester
1 2 Z C1 C2 C3 C4 C5 Collab-1 Collab-2Collab-3 Collab-4 OOAD Implementation C1 C2 C3 C4 C5 No language constructs that capture collaborations.
Quality Assurance in the Presence of Variability Kim Lauenroth, Andreas Metzger, Klaus Pohl Institute for Computer Science and Business Information Systems.
R-customizers Goal: define relation between graph and its customizers, study domains of adaptive programs, merging of interface class graphs.
Talk only to your friends that share the same concerns (Law of Demeter for Concerns) Midterm Review February 2004.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Principles of Programming & Software Engineering
Certification of Reusable Software Artifacts
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Design Patterns: MORE Examples
Recursion Topic 5.
Coupling and Cohesion Rajni Bhalla.
Algorithms II Software Development Life-Cycle.
John D. McGregor Session 9 Testing Vocabulary
C++ Templates.
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
Introduction to Design Patterns
Principles of Programming and Software Engineering
CSC 421: Algorithm Design & Analysis
Hierarchical Architecture
Lecture 2 of Computer Science II
Demeter Aspects Who We Are Aspectual Collaborations
TIM 58 Chapter 8: Class and Method Design
Adaptive Plug and Play Components for
Adaptive Object-Oriented Software Development
John D. McGregor Session 9 Testing Vocabulary
Software Design and Development
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
Adaptive Plug and Play Components for
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Lectures on Graph Algorithms: searching, testing and sorting
AP/DJ AP: a generic technology
Lecture 21: Crosscutting Aspect-Oriented Programming Background
An Introduction to Software Architecture
Adaptive Plug and Play Components for
Better Separation of Crosscutting Concerns with Aspectual Components
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
Requirements for better object-oriented design and programming languages Could be organized better.
APPCs revisited 2/25/2019 APPCs revisited.
Introduction to Data Structure
CSC 421: Algorithm Design & Analysis
Design Yaodong Bi.
Programming Languages, Preliminaries, History & Evolution
Adaptive Programming in JAsCo
Law of Demeter (LoD) 7/23/2019 LoD
From Use Cases to Implementation
Lecture 3 – Data collection List ADT
Presentation transcript:

Generic Programming using Adaptive and Aspect-Oriented Programming Karl Lieberherr, The Demeter Group College of Computer Science Northeastern University, Boston 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Overview Generic programming Aspect-oriented and Adaptive Programming Adaptive Plug-and-Play Components Pricing Policies (from an IBM code generator) Graph Algorithms (Cycle checking) Demeter/Java Conclusions 9/21/2018 Generic Programming/Dagstuhl

What is Generic Programming? Expressing algorithms with minimal assumptions about data abstractions, and vice versa, thus making them as interoperable as possible Lifting of a concrete algorithm to as a general level as possible without losing efficiency 9/21/2018 Generic Programming/Dagstuhl

What is Generic Programming? Lifting of a concrete algorithm to as a general level as possible without losing efficiency i.e., the most abstract form such that when specialized back to the concrete case the result is just as efficient as the original algorithm. From Dagstuhl 98 conference on generic programming 9/21/2018 Generic Programming/Dagstuhl

What is Generic Programming? Generic programming is about making programs more adaptable by making them more general Embody non-traditional kinds of polymorphism Parameters of a generic program are rich in structure (programs, types, graphs). From Workshop on Gen. Prog. Sweden 98 9/21/2018 Generic Programming/Dagstuhl

How does Aspect-Oriented Programming help? Tease out bigger chunks than classes Tease out issues which cross-cut many classes Describe different issues separately making minimal assumptions among them: Avoid tangling of issues Express issues by aspect descriptions which are compiled into behavior by a weaver 9/21/2018 Generic Programming/Dagstuhl

Many evolution problems come from tangled designs/programs Code for a requirement is spread through many artifacts. In each artifact, code for different requirements is tangled together. For example: Information structure is tangled with behavior. We want structure-shyness (Lieberherr ‘92). Synchronization code is tangled with sequential code. 9/21/2018 Generic Programming/Dagstuhl

Eliminating drawbacks with Aspect-Oriented Programming (AOP) Solution: Split software into cooperating, loosely coupled components and aspect-descriptions. Untangles designs/programs and eliminates redundancy. Aspect description examples: marshalling, synchronization, information structure etc. 9/21/2018 Generic Programming/Dagstuhl

Cross-cutting of components and aspects better program easier to understand! ordinary program structure-shy functionality Components structure Aspect 1 avoid tangled programs AOP synchronization Aspect 2 9/21/2018 Generic Programming/Dagstuhl

What is adaptive programming (AP)? A special case of AOP One of the aspects or the components use graphs which are referred to by traversal strategies. A traversal strategy defines traversals of graphs without referring to the details. Adaptive programming is aspect-oriented programming with traversal strategies. 9/21/2018 Generic Programming/Dagstuhl

Flexibility versus Complexity AP adds flexibility BUT simplifies designs and programs Partial evaluation makes efficient 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Families: Nature Analogy for AP same seeds in different climates: similar trees same strategy in different class graphs: similar traversals warm climate cold climate 9/21/2018 Generic Programming/Dagstuhl

Why Traversal Strategies? Law of Demeter: a method should talk only to its friends: arguments and part objects (computed or stored) and newly created objects Dilemma: If followed: Small method problem of OO If not followed: Unmaintainable code Traversal strategies are the solution to this dilemma 10 year anniversary Widely used, for example, at JPL for the Mars exploration software. problem solved by traversal strategies Graph patterns: for implementing patterns 9/21/2018 Generic Programming/Dagstuhl

Software Architecture View Software architectures where connections necessary for a specific behavior are specified approximately, yet precisely, using regular expression-like constructs. Improves on conventional architectures by supporting structure-shyness allowing both simpler and more flexible architectures. 9/21/2018 Generic Programming/Dagstuhl

Implementation of traversal strategies Based on novel applications and variations of standard techniques: Intersection of non-deterministic finite automata Simulation of non-deterministic finite automata 9/21/2018 Generic Programming/Dagstuhl

How to do the interesting work? Traversal strategies only navigate. Visitors and adaptive plug and play components (APPCs) specify what is done in addition to navigation. APPCs change group of classes during a traversal plug-and-play organization based on ports parameterized by traversal strategies 9/21/2018 Generic Programming/Dagstuhl

Adaptive Plug-and-Play Components (APCCs) Specify two interfaces to the class structure they are supposed to visit to other APPCs they may be connected to 9/21/2018 Generic Programming/Dagstuhl

Pricing Policies with APPCs APPC Pricing Interface s1 = from lineItem: LineItemParty via item: ItemParty to charges: ChargesParty; s2 = from lineItem: LineItemParty to pricer: PricerParty; s3 = from lineItem: LineItemParty to customer: Customer; PricerParty [ Float basicPrice(ItemParty item); Integer discount(ItemParty item, Integer qty, Customer: customer); ] ChargesParty [ Float cost(Integer qty, Float unitP, ItemParty: item ); ] 9/21/2018 Generic Programming/Dagstuhl

Pricing Policies with APPCs APPC Pricing Behavior LineItemParty { public Float price (Integer qty ){ Float basicPrice, unitPrice; Integer discount; basicPrice = pricer.basicPrice(); discount = pricer.discount(item, qty, customer); unitPrice = basicPrice - (discount * basicPrice); return (unitprice + additionalCharges(unitPrice, qty)); } Float additionalCharges(float unitP, Integer qty) { Interger total = 0; during s1 { ChargesParty{total += cost(qty, unitP, item); } return total;} } } 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl 9/21/2018 Generic Programming/Dagstuhl

Pricing Policies with APPCs Let us generate different pricing schemes out of the generic pricing component specified by the pricing adaptive plug-and-play component … Scheme 1: Regular Pricing each product has a base price which can be discounted depending on the number of the units ordered Scheme 2: Negotiated Pricing: A customer may have negotiated certain prices and discounts for particular items 9/21/2018 Generic Programming/Dagstuhl

Pricing Policies with APPCs Scheme 1: Regular Price Quote::+ {float regPrice() = Pricing with { LineItemParty = Quote; PriceParty = HWProduct [basicPrice = regPrice; discount = regDiscount;] ItemParty = HWProduct; ChargesParty = Tax [cost = taxCharge] } Roles LineItemParty PriceParty ItemParty ChargesParty Played by Quote HWProduct Tax 9/21/2018 Generic Programming/Dagstuhl

Pricing Policies with APPCs Scheme 2: Negotiated Price Quote::+ {Float negPrice() = Pricing with { LineItemParty = Quote; PriceParty = Customer; [basicPrice = negProdPrice; discount = negProdDiscount;] ItemParty = HWProduct; ChargesParty = Tax; [cost = taxCharge] } Roles LineItemParty PriceParty ItemParty ChargesParty Played by Quote Customer HWProduct Tax 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl APPC Compositions Graph algorithms Marking: Basic Marking Algorithm Cycle: Cycle Checking addition Connected: Connected Component Addition 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Composing APPCs APPC Marking { Interface s = from Graph to Adjacency to Vertex to Adjacency Behavior Adjacency { bool marked = false; myRole() { bool visited = marked; if (marked == false) { marked = true; next()}; return visited;} } 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Composing APPCs APPC Connectivity { Interface s: from Graph to-stop Adjacency Behavior Integer count = 0; return count; Adjacency { myRole() { if ( next() == false ) { count += 1; } } } 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Composing APPCs APPC CycleCheck { Interface s = from Graph to Adjacency to Vertex to Adjacency Behavior Stack stack = Stack new(); Adjacency { myRole() { if (stack.includes(this)) { System.out.printIn(``cycle'' + stack.print) } else { stack.add(this); } next(); stack.remove(this); } 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Composing APPCs Want to do connectivity and cycle check simultaneously 9/21/2018 Generic Programming/Dagstuhl

Instantiating APPC Compositions ConnectivityAndCycleCheck = (Connectivity compose DGCycleCheck) (Marking) (Connectivity => CycleCheck => Marking, {Connectivity, CycleCheck} <= Marking) // INSTANTIATING FOR CONCRETE GRAPH STRUCTURE s = Network via Adjacency through neighbors via Node through <-source to Adjacency Network ::+ {void connectivityAndCycleCheck() = ConnectivityAndCycleCheck during s} with {Network = Graph; Node = Vertex; } 9/21/2018 Generic Programming/Dagstuhl

Adaptive Plug-and-Play Components Builds on Batory’s mixin layers (ECOOP 98) and supports adaptiveness by parameterization with traversal strategies Modification of a group of collaborating classes Encapsulate group of related adaptive programs 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Tools using Demeter ideas: Demeter/C++, Demeter/CLOS (BBN), Demeter/Perl5 (MIT), AspectJ (Xerox PARC) Goal of Demeter/Java Avoid code tangling and redundancy traversal strategies and visitors untangle structure and behavior visitors and adjusters untangle code for distinct behaviors COOL untangles synchronization issues and behavior RIDL untangles remote invocation issues and behavior and structure 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Success indicators Used in several commercial projects (HP (printer family installation), GTE (compiler), Motorola (pattern generator), Novell (schema comparator) AspectJ from Xerox PARC based on Cristina Lopes Ph.D. thesis (1998) at Northeastern University supported by Xerox PARC. 9/21/2018 Generic Programming/Dagstuhl

Success indicators: Commercialization effort StructureBuilder from Tendril Software Inc. Has support for traversals and generates code controlled by structure. Neeraj Sangal, CEO www.tendril.com 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Conclusions APPCs as a useful abstraction for generic programming How to use them with C++ and STL: simulate them using the visitor design pattern Traversal strategies are a key component of APPCs 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Some Connections Complete traversals: APPCs need that too Polytypic Programming: APPCs are polytypic Konstanz team: Generic graph algorithms: APPCs seem to help Traversal Strategy Graphs: can be explained in terms of temporal logic (CTL formulas) 9/21/2018 Generic Programming/Dagstuhl

Partial Evaluation: Ray Tracing Viewpoint determines how scene appears. Avoid recomputations from viewpoint to viewpoint (imagine flying over scene). For example, intersection of objects can be computed once and reused for several viewpoints. 9/21/2018 Generic Programming/Dagstuhl

Partial Evaluation: Ray Tracing Scene(S) ViewPoint(VP) ViewPoint(VP) P(S,VP) P(VP) S fixed Scene with light info Scene with light info 9/21/2018 Generic Programming/Dagstuhl

Partial Evaluation: Ray Tracing Scene(S) ViewPoint(VP) ViewPoint(VP) P(VP) S fixed In C P(S,VP) PE for C PE for C PE for C Scene with light info in C Output = Scene with light info in C 9/21/2018 Generic Programming/Dagstuhl

Partial Evaluation: Adaptive Programming Component SG CG OG OG P(SG,CG,OG) P(OG) CG fixed SG fixed APPCs fixed APPCs ClassGraph CG ObjectGraph OG StrategyGraph SG PE for graph language PE for graph language Output = Graph Language with code annotations Output 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Similarities Ray tracing freeze scene transform program to gain efficiency domain specific computation use general partial evaluation algorithms AP freeze class graph freeze strategy graph transform program to gain efficiency general-purpose computation use specialized partial evaluation algorithms (automata intersection) 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Similarities Ray tracing use general partial evaluation algorithms for a programming language such as C. AP use specialized partial evaluation algorithms (automata intersection) partial evaluation is done for a graph language 9/21/2018 Generic Programming/Dagstuhl

Partial Evaluation: Adaptive Programming Component CG’ OG SG CG OG P(CG’,OG) CG partially fixed SG fixed P(SG,CG,OG) ClassGraph CG ObjectGraph OG StrategyGraph SG Output Output 9/21/2018 Generic Programming/Dagstuhl

Aspect-Oriented Programming 9/21/2018 Generic Programming/Dagstuhl

Aspect-Oriented Programming Background aspects synchronization remote invocation Foreground aspects visitors APPCs 9/21/2018 Generic Programming/Dagstuhl

Aspect-Oriented Programming Implementation requires special purpose partial evaluators. Example: P(SG,CG,OG) P(OG) CG fixed SG fixed PE for graph language 9/21/2018 Generic Programming/Dagstuhl

Aspect-Oriented Programming Expansion of aspect description bounded synchronization unbounded structure 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl STL view data structures algorithms glue = iterators parameterized by iterators 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Demeter view adaptive algorithms data structures glue = traversal strategies 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Demeter view 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Demeter View Adaptive program: strategies as parameters Class graph: intended home for traversal strategies Glue = traversal strategies = adapt strategy parameters to specific class graph and check constraints 9/21/2018 Generic Programming/Dagstuhl

Traversal strategy types Traversal strategy parameters have an interface a traversal strategy without negative constraints express minimal relationships needed CTL expressions for ordering constraints (optional) 9/21/2018 Generic Programming/Dagstuhl

Modification of objects during traversal Validity of a traversal insertion or deletion at point to be traversed at point already traversed 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Plug-and-play Has a specific meaning Self description Building blocks are enabled to find their own collaborators Popular in hardware 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl APPCs and composition Should be able to write programs to compose and configure APPCs? Ullrich Koethe: It is sometimes time consuming and error prone to set up collaborations manually. Often, selecting one collaborator implies certain choices of other, related services. If these constraints must be kept manually => reduced reusability 9/21/2018 Generic Programming/Dagstuhl

Generic Programming/Dagstuhl Composition of APPCs A => B => C {A,B} <= C Not good enough: Need conditionals, loops, arrays to connect components. 9/21/2018 Generic Programming/Dagstuhl