AP/DJ AP: a generic technology

Slides:



Advertisements
Similar presentations
DJ Example in UAV Context Karl Lieberherr. Frame Structure Frame X1 X2X3X4X5 AX6X7BX8 Annotation.
Advertisements

. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
1 L41 Collections (1). 2 OBJECTIVES  What collections are.  To use class Arrays for array manipulations.  To use the collections framework (prepackaged.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
1 Iterators & Algorithms Iterators provide a link between containers and algorithms Example: We wish to write a function sum() that adds up the members.
Object-Oriented Analysis and Design
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
AP/DJ AP: a generic technology DJ: a low-learning-curve implementation of AP.
Generic Programming Using the C++ Standard Template Library.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Law of Demeter. What is it: Style Rule for building systems. Proposed by my research group: The Demeter Research Group in 1987, published in Covered.
Data structures Abstract data types Java classes for Data structures and ADTs.
Not only mark-up languages! There are other many other grammar formalisms and tools than XML. Some of them standardized (ASN). Even XML does not always.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Iterators Good reference site:
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
Intro to the C++ STL Timmie Smith September 6, 2001.
Translating Traversals to AspectJ. Outline Motivation Demeter Process for Traversals AspectJ Translation Process.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
DJ: traversal-visitor-style programming in Java Josh Marshall/ Doug Orleans Want to add more on traversal through collections and Aspectual Components.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
Problem with Java and how it causes a problem for DJ.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
R-customizers Goal: define relation between graph and its customizers, study domains of adaptive programs, merging of interface class graphs.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
The Law of Demeter For Operating System Course. Motivation Several programs were written in bad style Are difficult to maintain There is a simple remedy.
Talk only to your friends that share the same concerns (Law of Demeter for Concerns) Midterm Review February 2004.
Lecture 7 Discuss midterm Scheduling. Alternative Directory Structure See hw 1 and hw 2. This one more aligned with UNIX directory structure. Idea for.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Linked Data Structures
String and Lists Dr. José M. Reyes Álamo.
CS212: Object Oriented Analysis and Design
Lecture 10 Collections Richard Gesick.
Topic 2: binary Trees COMP2003J: Data Structures and Algorithms 2
Regarding homework 9 Many low grades
Programming with ANSI C ++
Good for DJ over Java Extending traversals for collections (b..*)
Containers and Lists CIS 40 – Introduction to Programming in Python
MA/CSSE 473 Day 13 Finish Topological Sort Permutation Generation
Chapter 1 OBJECT-ORIENTED ANALYSIS AND DESIGN
Hashing Exercises.
Java Algorithms.
The Law of Demeter (LoD) and how it should be used
structures and their relationships." - Linus Torvalds
Chapter 15 QUERY EXECUTION.
Hash table another data structure for implementing a map or a set
CS313D: Advanced Programming Language
structures and their relationships." - Linus Torvalds
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
Copyright © Aiman Hanna All rights reserved
AP/DJ AP: a generic technology
String and Lists Dr. José M. Reyes Álamo.
Asst. Dr.Surasak Mungsing
ArrayLists 22-Feb-19.
Fundaments of Game Design
Standard Template Library
Karl Lieberherr Doug Orleans
Standard Template Library
Law of Demeter (LoD) 7/23/2019 LoD
structures and their relationships." - Linus Torvalds
SPL – PS1 Introduction to C++.
A dictionary lookup mechanism
Presentation transcript:

AP/DJ AP: a generic technology DJ: a low-learning-curve implementation of AP

Law of Demeter Principle Each unit should only have limited knowledge about other units: only about units “closely” related to the current unit. “Each unit should only talk to its friends.” “Don’t talk to strangers.” Main Motivation: Control information overload. We can only keep a limited set of items in short-term memory.

Law of Demeter FRIENDS

Application to OO Unit = method closely related = methods of class of this/self and other argument classes methods of immediate part classes (classes that are return types of methods of class of this/self) In the following we talk about this application of the Law of Demeter Principle to OO

Rumbaugh and the Law of Demeter Quote: Avoid traversing multiple links or methods. A method should have limited knowledge of an object model. A method must be able to traverse links to obtain its neighbors and must be able to call operations on them, but it should not traverse a second link from the neighbor to a third class.

Law of Demeter (alternative formulation) A method should have limited knowledge of an object model. AP is a reaction to this view of the Law of Demeter

Agreement that LoD Good Idea How to follow LoD: good solutions exist but not widely known. Two approaches to following LoD: OO approach Adaptive approaches DJ APPC Demeter/Java

What if your friends are far away? You pay them to travel to you or you send an agent to them to collect the information you need. Approximate Directions: You give them or your agent directions about what kind of information to collect but you don’t care about accidental details of the travel. Detailed Directions: You give them or your agent detailed travel directions.

Adaptive Following LoD C A FRIENDS a S X c b a:From S to A b:From S to B c:From S via X to C

Traversal specifications create friends Class ClassGraph is an intermediate class between classes that need to communicate ClassGraph.fetch(Object o, TravSpec s)

Adaptive Following of LoD: Key Idea Collaborations are not explicit in the software. This is what APPCs will support. So why?

DJ An implementation of AP using only the DJ library and the Java Generic Library (JGL) All programs written in pure Java Intended as prototyping tool: makes heavy use of introspection in Java Integrates Generic Programming (a la STL) and Adaptive programming

Integration of Generic and Adaptive Programming A traversal specification turns an object graph into a container. Can invoke 50+ generic algorithms on those containers. Examples: add, delete, find, etc. What is gained: genericity not only with respect to data structure implementations but also with respect to class graph

Algorithm Classes Applying Applies a function to every element of a sequence Comparing Mismatches, performs equality tests, performs lexicographical comparisons Copying Copies a sequence Counting Counts unconditionally and conditionally Filling Fills a sequence with a single element Filtering Filters a sequence Finding Finds an object or an element that satisfies a predicate

Algorithm Classes Hashing Contains generic hashing algorithms Heap Makes, pushes, pops, and sorts a heap MinMax Finds the min and max of a sequence OrderSetOperations Contains Generic set operation algorithms Permuting Cycles through permutations of a sequence Printing Prints sequences and containers Removing Removes an object or element that satisfies a predicate

Algorithm Classes Replacing Replaces an object or element that satisfies a predicate Reversing Reverses a sequence Rotating Rotates a sequence SetOperations Union, intersection, difference, and inclusion Shuffling Shuffles a sequence Sorting Sorts a sequence Swapping Swaps elements or sequences Transforming Maps one sequence to another

Collections JGL includes 11 highly optimized data structures that satisfy most programmer needs. These data structures have been engineered for performance and ease of use, and their performance either meets or beats every other commercially available Java container library. In addition, all JGL containers work correctly in multithreaded situations.

Collection Interface add(Object) Add an object to myself. clear() Remove all of my objects. clone() Return a shallow copy of myself. elements() Return an Enumeration of the components in this container equals(Object) Return true if I'm equal to a specified object. finish() Return an iterator positioned immediately after my last item.

Collection Interface isEmpty() Return true if I contain no objects. maxSize() Return the maximum number of objects that I can contain. remove(Enumeration) Remove the element at a particular position. remove(Enumeration, Enumeration) Remove the elements in the specified range. size() Return the number of objects that I contain. start() Return an iterator positioned at my first item. toString() Return a string that describes me.

com.objectspace.jgl.algorithms. Filtering reject(Container, UnaryPredicate) Reject elements in a container. reject(InputIterator, InputIterator, UnaryPredicate) Reject elements in a range. select(Container, UnaryPredicate) Select elements in a container. select(InputIterator, InputIterator, UnaryPredicate) Select elements in a range. …

com.objectspace.jgl.algorithms. Permuting nextPermutation(BidirectionalIterator, BidirectionalIterator, BinaryPredicate) Arrange a sequence to become its next permutation. nextPermutation(Container, BinaryPredicate) Arrange a container to become its next permutation. prevPermutation(BidirectionalIterator, BidirectionalIterator, BinaryPredicate) Arrange a sequence to become its previous permutation. prevPermutation(Container, BinaryPredicate) Arrange a container to become its previous permutation.

com.objectspace.jgl.algorithms. Transforming collect(Container, UnaryFunction) Return a container that is the same class as the original and contains the result of applying the given unary function to each element in the original. transform(Container, Container, Container, BinaryFunction) Traverse two containers and add the results of invoking a BinaryFunction on corresponding elements to another container.

Sample DJ code // Find the user with the specified uid Container libUsers = new Container(library, "from Library to User"); User user = libUsers.find("uid", uid); Check???

Methods provided by DJ On all objects: traverse, fetch, gather On containers: Java Generic Library algorithms (in progress) traverse is the important method; fetch and gather are special cases

Traverse method: excellent support for Visitor Pattern // class ClassGraph Object traverse(Object o, Strategy s, Visitor v); traverse navigates through Object o following traversal specification s and executing the before and after methods in visitor v ClassGraph is computed using introspection

Guidelines Abreviations IF you plan to use 1 sg with 1 o and several v THEN freeze(cg,sg,o)->ogs 1 sg with several (o or v) THEN freeze(cg,sg)->tg 1 o with several (sg or v) THEN freeze(cg,o)->og 1 tg with 1 o and several v THEN freeze(tg,o)->ogs 1 sg with 1 (o and v) THEN inline cg class graph s strategy tg traversal graph o object og object graph ogs object graph slice v visitor or generic algorithm Abreviations

DJ binaryconstruction operations

Who has traverse, fetch, gather? (number of arguments of traverse)

Methods returning an ObjectGraphSlice ClassGraph.slice(Object, Strategy) ObjectGraph.slice(Strategy) TraversalGraph.slice(Object) ObjectGraphSlice(ObjectGraph,Strategy) ObjectGraphSlice(ObjectGraph,TraversalGraph) Blue: constructors

Traverse method arguments ClassGraph Object, Strategy, Visitor TraversalGraph Object, Visitor ObjectGraph Strategy, Visitor ObjectGraphSlice Visitor

Traverse method arguments. Where is collection framework used? ClassGraph Object, Strategy, Visitor TraversalGraph Object, Visitor / asList(Object) ObjectGraph Strategy, Visitor / asList(Strategy) ObjectGraphSlice Visitor / asList()

Where is collection framework used?

DJ unary construction operations Class graph from TraversalGraph Class graph from all classes in package

Lack of parameterized classes in Java makes DJ harder to use Consider the traversal: from A to B Let’s assume that in the class graph between A and B there is a Java collection class. The intent is: A = List(B) which we cannot express in Java. Instead we have: A = Vector(Object). Object : A | B. Let’s assume we also have a class X=B.

Lack of parameterized classes in Java makes DJ harder to use We have: A = Vector(Object). Object : A | B | X. X = B. If the vector contains an X object it will be traversed!!! Vector * Object A X B

No X-object is allowed to be in vector A * X B Vector * Object A X B

Moral of the story If the Collection objects contain only the objects advertised in the nice class graph of the application the traversal done by DJ will be correct. However, if the Collection objects contain additional objects (like an X-object) they might be traversed accidentally.

Size of traversal graph DJ might create big traversal graphs when collection classes are involved. DJ will plan for all possibilities even though only a small subset will be realized during execution. To reduce the size of the traversal graph, you need to use bypassing. In the example: from A bypassing {A,X} to B.

More info DJ Home Page