Software Development CSU 670 www ccs neu eduhomeliebercoursescsu
Software Development CSU 670 www. ccs. neu. edu/home/lieber/courses/csu 670/f 03. html 9/18/2021 CSU 670/1 1
Introduction • Software engineering, modeling, design, software architecture, software processes • Programming languages • Hands-on, practical, useful 9/18/2021 CSU 670/1 2
Summary of Course • How to design and implement flexible objectoriented software using the principles of adaptiveness and separation of concerns in combination with UML and Java. Learning principles behind XML. • How to design and implement flexible 100% pure Java software minimizing scattering and tangling of crosscutting behavioral concerns. 9/18/2021 CSU 670/1 3
Who is in Attendance? • Software developers who have experience with object-oriented programming. • Should know concepts of OOP, like classes, methods, and late binding. • Software developers who know about formal languages and automata: grammars, non-terminals, terminals. 9/18/2021 CSU 670/1 4
Academic Integrity • Tension – Learning from your peers: is valuable • for technical help; “this program does not run properly and I have tried for two hours to figure out why; can I explain my program to you? ” • for discussing ways to think about the concepts • for home work and project work if you work in a team of two (encouraged: pair programming!) • for getting a concept explained • for sharing frustrations – Independent scholarship 9/18/2021 CSU 670/1 5
Academic Integrity – Independent scholarship • Required for exams • Required for giving presentations in class • Required for succeeding 9/18/2021 CSU 670/1 6
Important Rules • Learn when to go inside and solve the problems yourself. • Learn when it is appropriate to use help from a peer. 9/18/2021 CSU 670/1 7
Featured in MIT Technology Magazine 2001 as a Top Ten Technology Agenda Demeter. J Java and DJ Java environment UML XML requirements domain analysis design implementation 9/18/2021 Aspect-Oriented Progr. Adaptive Programming principles heuristics patterns idioms theorems algorithms Demeter Method iterative development spiral model Extreme Programming CSU 670/1 strategy graphs class graphs object graphs state graphs use cases interfaces traversals visitors packages 8
Aspect-Oriented Software Development (AOSD) • Observation: many concerns of the designer/programmer are scattered across many classes or methods and tangled with code of other concerns. • A concern is called crosscutting, if its ad-hoc implementation is scattered. • AOSD is about cleanly modularizing crosscutting concerns. A modularized crosscutting concern is called an aspect. • Reduces scattering and tangling. 9/18/2021 CSU 670/1 9
Agenda • UML class diagrams. Perspective: analysis, design, implementation • Class graphs as special cases of UML class diagrams • Textual representation of class graphs • Default implementation of UML class diagrams as class graphs 9/18/2021 CSU 670/1 10
Agenda • UML interaction diagrams – sequence diagrams – collaboration diagrams – improving interaction diagrams to make them specification languages • XML data type definitions and documents 9/18/2021 CSU 670/1 11
Agenda • Class graphs in textual form (construction, alternation) • object graphs (graphical and textual form) • object graphs defined by class graphs • add repetition classes and optional parts • translating class graphs to Java 9/18/2021 CSU 670/1 12
Agenda • annotating class graph with syntax: class dictionary • printing objects and language defined by class dictionary • grammars, parsing, ambiguous grammars, undecidable problem • LL(1) grammars, robustness of sentences • etc. 9/18/2021 CSU 670/1 13
Overview • good separation of concerns is the goal • concerns should be cleanly localized • programs should look like designs 9/18/2021 CSU 670/1 14
Adaptive Programming • Programs adapt to interesting context changes • Structure-shy behavior • Succinct representation of traversals • Programming in terms of graph constraints 9/18/2021 CSU 670/1 15
Cross-cutting of concerns ordinary program better program structure-shy functionality structure synchronization 9/18/2021 CSU 670/1 Components Aspect 1 Aspect 2 16
interface Shape. I extends Remote { double get_x() throws Remote. Exception ; void set_x(int x) throws Remote. Exception ; double get_y() throws Remote. Exception ; void set_y(int y) throws Remote. Exception ; double get_width() throws Remote. Exception ; void set_width(int w) throws Remote. Exception ; double get_height() throws Remote. Exception ; void set_height(int h) throws Remote. Exception ; void adjust. Location() throws Remote. Exception ; void adjust. Dimensions() throws Remote. Exception ; } public class Shape implements Shape. I { protected Adjustable. Location loc; protected Adjustable. Dimension dim; public Shape() { loc = new Adjustable. Location(0, 0); dim = new Adjustable. Dimension(0, 0); } double get_x() throws Remote. Exception { return loc. x(); } void set_x(int x) throws Remote. Exception { loc. set_x(); } double get_y() throws Remote. Exception { return loc. y(); } void set_y(int y) throws Remote. Exception { loc. set_y(); } double get_width() throws Remote. Exception { return dim. width(); } void set_width(int w) throws Remote. Exception { dim. set_w(); } double get_height() throws Remote. Exception { return dim. height(); } void set_height(int h) throws Remote. Exception { dim. set_h(); } void adjust. Location() throws Remote. Exception { loc. adjust(); } void adjust. Dimensions() throws Remote. Exception { dim. adjust(); } } class Adjustable. Location { protected double x_, y_; public Adjustable. Location(double x, double y) { x_ = x; y_ = y; } synchronized double get_x() { return x_; } synchronized void set_x(int x) {x_ = x; } synchronized double get_y() { return y_; } synchronized void set_y(int y) {y_ = y; } synchronized void adjust() { x_ = long. Calculation 1(); y_ = long. Calculation 2(); } } class Adjustable. Dimension { protected double width_=0. 0, height_=0. 0; public Adjustable. Dimension(double h, double w) { height_ = h; width_ = w; } synchronized double get_width() { return width_; } synchronized void set_w(int w) {width_ = w; } synchronized double get_height() { return height_; } synchronized void set_h(int h) {height_ = h; } synchronized void adjust() { width_ = long. Calculation 3(); height_ = long. Calculation 4(); } } 9/18/2021 Modularization of crosscutting concerns public class Shape { protected double x_= 0. 0, y_= 0. 0; protected double width_=0. 0, height_=0. 0; Write this Instead of writing this CSU 670/1 double get_x() { return x_(); } void set_x(int x) { x_ = x; } double get_y() { return y_(); } void set_y(int y) { y_ = y; } double get_width(){ return width_(); } void set_width(int w) { width_ = w; } double get_height(){ return height_(); } void set_height(int h) { height_ = h; } void adjust. Location() { x_ = long. Calculation 1(); y_ = long. Calculation 2(); } void adjust. Dimensions() { width_ = long. Calculation 3(); height_ = long. Calculation 4(); } } coordinator Shape { selfex adjust. Location, adjust. Dimensions; mutex {adjust. Location, get_x, set_x, get_y, set_y}; mutex {adjust. Dimensions, get_width, get_height, set_width, set_height}; } portal Shape { double get_x() {} ; void set_x(int x) {}; double get_y() {}; void set_y(int y) {}; double get_width() {}; void set_width(int w) {}; double get_height() {}; void set_height(int h) {}; void adjust. Location() {}; void adjust. Dimensions() {}; } 17
Aspect-Oriented Programming components and aspect descriptions High-level view, implementation may be different Source Code (tangled code) weaver (compiletime) 9/18/2021 CSU 670/1 18
Examples of Aspects • • Collaborations, use cases Synchronization of methods across classes Remote invocation (using Java RMI) Quality of Service (Qo. S) Failure handling External use (e. g. , being a Java bean) Replication, Migration 9/18/2021 CSU 670/1 19
Connections • explain adaptive programming in terms of patterns • Aspect-Oriented Programming (AOP) is a generalization of Adaptive Programming (AP) • correspondence: adaptive program : object-oriented program = sentence : object graph 9/18/2021 CSU 670/1 20
Vocabulary • • • Graph, nodes, edges, labels Class graph, construction, alternation Object graph, satisfying class graph UML class diagram Grammar, printing, parsing 9/18/2021 CSU 670/1 21
Vocabulary • Traversals, visitors • Strategy graphs, path set 9/18/2021 CSU 670/1 22
Overview this lecture • • • Basic UML class diagrams Traversals/Collaborating classes Traversal strategy graphs Adaptive programming Tools for adaptive programming Demeter. J and AP/Studio 9/18/2021 CSU 670/1 23
1: Basic UML class diagrams • Graph with nodes and directed edges and labels for nodes and edges • Nodes: classes, edges: relationships • labels: class kind, edge kind, cardinality 9/18/2021 CSU 670/1 24
UML Class Diagram bus. Stops Bus. Route Bus. Stop. List buses 0. . * Bus. Stop Bus. List 0. . * passengers Bus Person. List Person 9/18/2021 waiting CSU 670/1 0. . * 25
2: Traversals / Collaborating classes • To process objects we need to traverse them • Traversal can be specified by a group of collaborating classes 9/18/2021 CSU 670/1 26
Collaborating Classes use connectivity in class graph to define them succinctly using strategy graphs from Company to Employee 9/18/2021 CSU 670/1 from Customer to Agent 27
OOAD self-service customer service center Z teller service Collab-1 C 2 C 4 C 3 C 5 Collab-2 C 1 C 2 C 4 C 3 Implementation C 5 9/18/2021 Collab-3 Collab-4 CSU 670/1 28
Collaborating Classes find all persons waiting at any bus stop on a bus route bus. Stops Bus. Route buses Bus. List 0. . * Bus. Stop. List OO solution: one method for each red class Bus. Stop waiting passengers Bus Person. List Person 9/18/2021 0. . * CSU 670/1 0. . * 29
TPP section: Decoupling and the Law of Demeter • Write shy code: • A shy person does not interact with too many people. • A shy method does not interact with too many classes/objects. 9/18/2021 CSU 670/1 30
3: Traversal Strategy Graphs • Want to define traversals succinctly • Use strategy graphs to express abstraction of class diagram • Express traversal intent: useful for documentation of object-oriented programs 9/18/2021 CSU 670/1 31
find all persons waiting at any bus stop on a bus route Traversal Strategy first try: from Bus. Route to Person bus. Stops Bus. Route Bus. Stop. List buses 0. . * Bus. Stop Bus. List 0. . * passengers Bus Person. List Person 9/18/2021 waiting CSU 670/1 0. . * 32
find all persons waiting at any bus stop on a bus route Traversal Strategy from Bus. Route through Bus. Stop to Person bus. Stops Bus. Route Bus. Stop. List buses 0. . * Bus. Stop Bus. List 0. . * passengers Bus Person. List Person 9/18/2021 waiting CSU 670/1 0. . * 33
find all persons waiting at any bus stop on a bus route Traversal Strategy Altern. : from Bus. Route bypassing Bus to Person bus. Stops Bus. Route Bus. Stop. List buses 0. . * Bus. Stop Bus. List 0. . * passengers Bus Person. List Person 9/18/2021 waiting CSU 670/1 0. . * 34
find all persons waiting at any bus stop on a bus route Robustness of Strategy from Bus. Route through Bus. Stop to Person Bus. Route villages busses Village. List 0. . * Bus. List Village 0. . * bus. Stops 0. . * Bus. Stop waiting passengers Bus Person. List Person 9/18/2021 Bus. Stop. List CSU 670/1 0. . * 35
Filter out noise in class diagram • only three out of seven classes are mentioned in traversal strategy! from Bus. Route through Bus. Stop to Person replaces traversal methods for the classes Bus. Route Village. List Village Bus. Stop. List Bus. Stop Person. List Person 9/18/2021 CSU 670/1 36
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: • Small method problem of OO (if followed) or • Unmaintainable code (if not followed) • Traversal strategies are the solution to this dilemma 9/18/2021 CSU 670/1 37
TPP: Tip 53: Abstractions Live Longer than Details • Is in the Requirements Pit section • Also applies to code: don’t overspecify! 9/18/2021 CSU 670/1 38
4: Adaptive Programming • How can we use strategies to program? • Need to do useful work besides traversing: visitors • Incremental behavior composition using visitors 9/18/2021 CSU 670/1 39
Styles of Adaptive Programming • Traditional: parameterize by class graph; strategy is part of adaptive program • Traditional optimized: parameterize by class graph and strategy graph; reuse pair of class graph and strategy graph. 9/18/2021 CSU 670/1 40
Writing Adaptive Programs with Strategies (DJ=pure Java) String WPS=“from Bus. Route through Bus. Stop to Person” class Bus. Route { int count. Persons(Class. Graph cg) { String WPS=“from Bus. Route through Bus. Stop to Person” Integer result = (Integer) cg. traverse(this, WPS, new Visitor(){ int r ; public void before(Person host){ r++; } public void start() { r = 0; } public Object get. Return. Value() {return new Integer ( r); } }); return result. int. Value(); } } 9/18/2021 CSU 670/1 41
Writing Adaptive Programs with Strategies (DJ=pure Java) // Prepare the class graph Class. Graph class. Graph = new Class. Graph(); int r = a. Bus. Route. count. Persons(class. Graph); 9/18/2021 CSU 670/1 42
TPP section: The Evils of Duplication • Tip 11: DRY – Don’t Repeat Yourself • Imposed duplication without tool support 9/18/2021 CSU 670/1 43
Goal of DJ • Focus on crosscutting traversal-related concerns: involve a group of collaborating objects which are manipulated to implement a behavior. • Provide a Java library to cleanly encapsulate crosscutting traversal-related concerns whose ad hoc implementation would be scattered across many classes. 9/18/2021 CSU 670/1 44
Solves Problem in AOP for Behavioral Aspects in Java • The Class. Graph-Aspect-Freezing problem – When we have n behavioral aspects and the class graph changes, we potentially need to update all n aspects. – DJ allows us to loosely couple behavioral aspects to the class graph. – And this is all done in Java using REFLECTION. 9/18/2021 CSU 670/1 45
Writing Adaptive Programs with Strategies (DJ=pure Java) String WPStrategy=“from Bus. Route through Bus. Stop to Person” class Bus. Route { int count. Persons(Traversal. Graph WP) { Integer result = (Integer) WP. traverse(this, new Visitor(){ int r ; public void before(Person host){ r++; } public void start() { r = 0; } public Object get. Return. Value() {return new Integer ( r); } }); return result. int. Value(); } } 9/18/2021 CSU 670/1 46
Writing Adaptive Programs with Strategies (DJ=pure Java) String WPStrategy=“from Bus. Route through Bus. Stop to Person” // Prepare the traversal for the current class graph Class. Graph class. Graph = new Class. Graph(); Traversal. Graph WPTraversal = new Traversal. Graph (WPStrategy, class. Graph); int r = a. Bus. Route. count. Persons(WPTraversal); 9/18/2021 CSU 670/1 47
Writing Adaptive Programs with Strategies (DJ=pure Java) class Utility { static int count. Persons(Object. Graph. Slice count. Slice){ Integer result = (Integer) count. Slice. traverse(new Visitor(){ int r ; public void before(Person host){ r++; } public void start() { r = 0; } public Object get. Return. Value() {return new Integer ( r); } }); return result. int. Value(); } } 9/18/2021 CSU 670/1 48
Writing Adaptive Programs with Strategies (DJ=pure Java) String WPStrategy=“from Bus. Route through Bus. Stop to Person” // Prepare the slice for the current class graph Class. Graph class. Graph = new Class. Graph(); Object. Graph object. Graph = new Object. Graph(a. Bus. Route, class. Graph); Object. Graph. Slice what. To. Count = new Object. Graph. Slice(object. Graph, WPStrategy); int r = Utility. count. Persons(what. To. Count); 9/18/2021 CSU 670/1 49
Writing Adaptive Programs with Strategies (Demeter. J) strategy: from Bus. Route through Bus. Stop to Person Bus. Route { int print. Count. Waiting. Persons() // traversal/visitor weaving through Bus. Stop to Person (Print. Person. Visitor); } Print. Person. Visitor { before Person {{ … }} … } Person. Visitor {init {{ r = 0; }} … } THIS IS NOT JAVA Extension of Java: keywords: init through bypassing to before after etc. 9/18/2021 CSU 670/1 50
Writing Adaptive Programs with Strategies (Demeter. J) strategy: from Bus. Route through Bus. Stop to Person Bus. Route { traversal waiting. Persons(Person. Visitor) { through Bus. Stop to Person; } // from is implicit int print. Count. Waiting. Persons() // traversal/visitor weaving = waiting. Persons(Print. Person. Visitor); } Print. Person. Visitor { before Person {{ … }} … } THIS IS NOT JAVA Person. Visitor {init {{ r = 0; }} … } Extension of Java: keywords: traversal init through bypassing to before after etc. 9/18/2021 CSU 670/1 51
Taxi driver analogy • Streets and intersections correspond to class graph • Traversal strategy determines how the taxi will navigate through the streets • You can take pictures before and after intersections • You can veto sub traversals 9/18/2021 CSU 670/1 52
Programming in Large Families Two adaptive programs A 1 Class Graphs A 2 A 1 family Object-Oriented Programs A 2 family 9/18/2021 CSU 670/1 53
Adaptive Programming Bold names refer to DJ classes. Strategy is use-case based abstraction of Class. Graph defines family of Object. Graph 9/18/2021 CSU 670/1 54
Adaptive Programming Strategy defines traversals of Object. Graph 9/18/2021 CSU 670/1 55
Adaptive Programming Strategy guides and informs Visitor 9/18/2021 CSU 670/1 56
Strategies Bus. Route Bus. Stop Person Nodes: positive information: Mark corner stones in class graph: Overall topology of collaborating classes. 3 nodes: from Bus. Route through Bus. Stop to Person 9/18/2021 CSU 670/1 57
Strategies bypassing edges incident with Bus. Route Person Edges: negative information: Delete edges from class graph. from Bus. Route bypassing Bus to Person 9/18/2021 CSU 670/1 58
5: Tools for Adaptive Programming • free and commercial tools available 9/18/2021 CSU 670/1 59
Free Tools on WWW • • DJ and AP Library Demeter/C++ Demeter. J Demeter/St. Klos Dem/Perl 5 Dem/C++ last four developed outside our group Dem/CLOS Demeter/Object Pascal 9/18/2021 CSU 670/1 60
Benefits of Adaptive Programming • robustness to changes • shorter programs • design matches program more understandable code • partially automated evolution • keep all benefits of OO technology • improved productivity Applicable to design and documentation of your current systems. 9/18/2021 CSU 670/1 61
Demeter. J • class diagrams • functionality • strategies • visitors • etc. www. ccs. neu. edu/research/demeter Executable Java code for your favorite commercial Java Software Development Environment weaver 9/18/2021 CSU 670/1 62
Demeter. J in Demeter. J structure (*. cd) class diagrams structure-shy communication (*. ridl) distribution compiler/ weaver synchronization (*. cool) multi threading 9/18/2021 CSU 670/1 focus of this lecture structure-shy behavior (*. beh) strategies and visitors structure-shy object description (*. input, at runtime) 63
Cross-cutting in Demeter. J generated Java program Demeter. J program structure-shy functionality structure replicated! synchronization 9/18/2021 CSU 670/1 64
AP Studio • visual development of traversal strategies relative to class diagram • visual feedback about collaborating classes • visual development of annotated UML class diagrams has not been used much 9/18/2021 CSU 670/1 65
Strengths of Demeter. J • Theory • Novel algorithms for strategies • Formal semantics • Correctness theorems • Practice • Extensive feedback • Reflective implementation 9/18/2021 CSU 670/1 66
Meeting the Needs • Demeter. J – Easier evolution of class diagrams (with strategy diagrams) – Easier evolution of behavior (with visitors) – Easier evolution of objects (with sentences) – Better separation of crosscutting traversalrelated concerns 9/18/2021 CSU 670/1 67
Real Life • Used in several commercial projects • Implemented by several independent developers • Used in several courses, both academic and commercial 9/18/2021 CSU 670/1 68
Summary • What has been learned: Simple UML class diagrams, strategies and adaptive programs • How can you apply: – Demeter. J takes adaptive programs as input – Document and implement object-oriented programs with strategies using DJ in Java – Design in terms of traversals and visitors 9/18/2021 CSU 670/1 69
Where to get more information • Adaptive Programming book • DJ home page • Demeter home page: www. ccs. neu. edu/research/demeter/ 9/18/2021 CSU 670/1 70
Feedback • Request feedback of training session 9/18/2021 CSU 670/1 71
- Slides: 71