Third lecture Review Visitor pattern DemeterJ 2/17/2019 SD.

Slides:



Advertisements
Similar presentations
Behavioral Pattern: Visitor C h a p t e r 5 – P a g e 224 When an algorithm is separated from an object structure upon which it operates, new operations.
Advertisements

Object Orientated Concepts. Overview  The world is objects  Defining an object  Not a function, it’s a method  Lets inherit want we can  Objects.
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
Visitor Pattern Jeff Schott CS590L Spring What is the Purpose of the Visitor Pattern ? n Represent an operation to be performed on the elements.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Visitor Matt G. Ellis. Intent Metsker: Let developers define a new operation for a hierarchy without changing the hierarchy classes. GoF: Represent an.
Design Patterns Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson,Ralph Johnson and John Vlissides (The Gang of.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
UML class diagrams and XML schemas Karl Lieberherr UBS AG Northeastern University.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Composit Pattern.
Extensible Plug-ins for Aspect-Oriented Programming Macneil Shonle*Ankit Shah.
Graph Visualization Plug-in for Eclipse Gong Jun CCIS Northeastern Univ 10/2003 How To Finish your Project within Four Weeks.
Go4 Visitor Pattern Presented By: Matt Wilson. Introduction 2  This presentation originated out of casual talk between former WMS “C++ Book Club” (defunct.
Slides for Gregor Kiczales Two versions –short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) –long version: Controlling.
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.
Design Patterns – II Lecture IV. Singleton Pattern Intent – Ensure a class only has one instance, and provide a global point of access to it Motivation.
John J. Sung TA Consulting. Motivation for TraversalJ KL Enterprises identified AOP Enter into the AOP market early Add value by adding traversals to.
....and other creepy things from John Vlissides The Visitor Pattern EXISTS! And its INTENT is to represent an operation to be performed on the elements.
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.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Wei-Tek Tsai who’s.
Translating Traversals to AspectJ. Outline Motivation Demeter Process for Traversals AspectJ Translation Process.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
DJ: traversal-visitor-style programming in Java Josh Marshall/ Doug Orleans Want to add more on traversal through collections and Aspectual Components.
Duke CPS Modules in Java l Classes that are related should be grouped together, may even share access to otherwise private methods/instance variables.
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
3 Project Objectives Aspectual Collaborations (AC) for the Connection Aspect –Metric: Does the restructuring of the UAV code with AC reduce the tangling.
UBC software modularity group 1/14/02 UCSD1 Discussion with Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what.
COM1205 TraversalJ Project* Pengcheng Wu Feb.25,2003.
Design Patterns (II) Lecture Three. Solution to Homework Two Used framework Used design patterns: composite and state Question: what are the differences.
AO Mechanisms in Demeter1 Discussion with Gregor Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what exists. An.
Talk only to your friends that share the same concerns (Law of Demeter for Concerns) Midterm Review February 2004.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Pattern Language for Adaptive Programming (AP)
Design Patterns Lecture part 2.
Chapter 11 Object-Oriented Design
Behavioral Design Patterns
OO Methodology OO Architecture.
Discussion with Gregor Kiczales at UBC
Demeter Aspects Who We Are Aspectual Collaborations
Design Patterns - A few examples
Lecture 6 Project review
A Short Introduction to Adaptive Programming (AP) for Java Programmers
Software Design and Development
DemeterJ Collaborative Behavior (using DJ) .prj ProjectControl
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
Jim Fawcett CSE776 – Design Patterns Summer 2003
Design Pattern: Visitor
Informatics 122 Software Design II
Award winning technologies
A Short Introduction to Adaptive Programming (AP) for Java Programmers
Third lecture Review Visitor pattern DemeterJ 12/25/2018 SD.
AP/DJ AP: a generic technology
Computer Science and Engineering
Computer Science and Engineering
Requirements for better object-oriented design and programming languages Could be organized better.
Introduction to AppInventor
APPCs revisited 2/25/2019 APPCs revisited.
Abstract Classes and Interfaces
Informatics 122 Software Design II
Software Design Lecture : 39.
16. Visitors SE2811 Software Component Design
16. Visitors SE2811 Software Component Design
Visitor Pattern Intent
Plug-In Architecture Pattern
Presentation transcript:

Third lecture Review Visitor pattern DemeterJ 2/17/2019 SD

DemeterJ in DemeterJ structure (*.cd) class diagrams structure-shy compiler/ weaver structure-shy behavior (*.beh) strategies and visitors structure-shy communication (*.ridl) distribution more details on Demeter components and aspects structure-shy object description (*.input, at runtime) synchronization (*.cool) multi threading 2/17/2019 SD

Example in DemeterJ class graph in program.cd: A = B. X : B. B : C | D common E. C = “c”. D = “d”. E = . 2/17/2019 SD

Behavior basically in DJ program.beh: Main { {{ // all Java code public static void main(Sring args[] … { A c = A.parse(“c”); A d = A.parse(“d”); ClassGraph cg = new ClassGraph(true,false); Visitor v = new Visitor() { void before (X host) {System.out.println(“x”);} void before (B host) {System.out.println(“b”);} void before (C host) {System.out.println(“c”);} }; System.out.println(“C-object:”); cg.traverse(c,”from A to C”,v); System.out.println(“D-object:”); cg.traverse(d,”from A to C”,v); } System.out.println(“Done.”); }} // end all Java code } 2/17/2019 SD

Output C-object: x b c D-object: Done. 2/17/2019 SD

Design Patterns for Collaborative Behavior Navigate composite object structure Iterator Traversal through a collection Define task-specific behavior Visitor 2/17/2019 SD

Visitor - Intent Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. 2/17/2019 SD

Visitor - Example 2/17/2019 SD

Visitor - Structure 2/17/2019 SD

Visitor - Applicability When an object structure contains many classes of objects with different interfaces, and you want to perform operations on objects that depend on their concrete classes. To avoid cluttering of classes. Visitor lets you keep related operations together. When the classes defining the object structure rarely change. 2/17/2019 SD

Visitor - Consequences It makes it easy to add new operations to an object structure. It gathers related operations and separates unrelated ones. Visitor can visit objects that do not have a common parent class. 2/17/2019 SD

Visitor - Consequences It makes it hard to add new classes in the object structure. 2/17/2019 SD

How does DJ help? With Standard Visitor: If k concrete element classes and m abstract element classes involved in traversal. Need k VisitConcreteElement(ConcreteElement) methods in abstract visitor. Need k+m accept methods, one in each element class. DJ: no abstract visit methods, no accept methods. 2/17/2019 SD

How does DJ help? DJ makes it easy to change the class structure when visitor pattern is used. DJ provides one universal visitor class. We don’t need a separate abstract visitor class for each behavior. DJ provides accept methods through the strategy. DJ is finer grained: before and after methods. 2/17/2019 SD

Visitor Pattern Intent: Modify the behavior of a group of collaborating classes without changing the classes. Examples: Inventory: accumulate list of equipment compute price In the following: Only Java, no Demeter 2/17/2019 SD

Visitor Pattern abstract class EquipmentVisitor{ abstract void visitCard(Card e); abstract void visitChassis(Chassis e); ... } 2/17/2019 SD

Visitor Pattern class PricingVisitor extends EquipmentVisitor{ private Currency total; void VisitCard(Card e){total.add(e.NetPrice());} void VisitChassis(Chassis e) {total.add(e.DiscountPrice());} … } 2/17/2019 SD

Visitor Design Pattern class InventoryVisitor extends EquipmentVisitor { Inventory inventory; void VisitCard(Card e) {inventory.accumulate(e);} void VisitChassis(Chassis e){ inventory.accumulate(e);} … } 2/17/2019 SD

Visitor class Card extends Equipment { void Accept(EquipmentVisitor v) {v.VisitCard(this);} … } 2/17/2019 SD

Visitor class Chassis { void Accept(EquipmentVisitor v){ v.VisitChassis(this); Enumeration e = parts.elements(); while (e.hasMoreElements()) ((Equipment) e.nextElement()). Accept(v); } 2/17/2019 SD

Visitor/Applicability Collaborative tasks Add behavior to composite structure 2/17/2019 SD

Visitor AbstractVisitor : ConcreteVisitor1 | ConcreteVisitor2. VisitConcreteA(ConcreteA); VisitConcreteB(ConcreteB); ConcreteA = … Accept(Visitor v) {v.VisitConcreteA(this); /* further traversal */ } 2/17/2019 SD

Visitor/Participants AbstractVisitor - empty visit operations ConcreteVisitor - task specific visit operation ConcreteElement - accept operation 2/17/2019 SD

Visitor Pros Add behavior to composite class structure without cluttering class definitions Cons Explicit traversal, hard-coding structure Auxiliary structure, many empty methods 2/17/2019 SD

Visitor hard changes: modify class structure add new concrete element class: need to update all visitors rename parts easy changes: add a new visitor 2/17/2019 SD

Improve Visitor by Selective Visitor Structure-shy Traversal before, after, around, not just accept no empty methods Structure-shy Traversal strategies 2/17/2019 SD

DemeterJ programming Now we focus on the structure and syntax of the DemeterJ programming language. It reuses Java unchanged. Java code between (@ and @) or {{ and }}. Provides syntax to define traversal strategies and visitors and how to glue the three together. 2/17/2019 SD

DemeterJ programming for simple use: prepare program.cd, program.beh, program.input call demeterj new (on UNIX and Windows): generates program.prj: be careful: program.prj~ demeterj test demeterj clean if you (and the system) are confused. Regenerates and recompiles. 2/17/2019 SD

DemeterJ programming Style for calling Java program: always use a class Main which contains a static public void main function. java -classpath gen/classes :… demjava.jar ... Main < program.input (Windows: /->\ :->; ) demeterj test will do the right thing 2/17/2019 SD

DemeterJ programming program.cd start it with a package name: package X; add package name to program.prj file. Call java X.Main < program.input import classes: import java.util.* terminate the start class with EOF (make sure class is not recursive) See DemeterJ class dictionary for syntax (see DemeterJ AP Studio resource page) 2/17/2019 SD

DemeterJ programming can also use look-ahead definitions as in Java Compiler Compiler. See Java class dictionary off DemeterJ resource page. Also Java Compiler Compiler home page. use look-ahead definitions only when absolutely needed. Most of the time you don’t need them. I avoid them. 2/17/2019 SD

DemeterJ programming Continue with programming of behavior 2/17/2019 SD

End of viewgraphs 2/17/2019 SD