CSU 670 Karl Lieberherr https://lists.ccs.neu.edu/bin/listinfo/ Software Development CSU 670 Karl Lieberherr https://lists.ccs.neu.edu/bin/listinfo/ First lecture, first class Sep25. 4/10/2019 CSU 670/1
Cross-cutting of concerns better program ordinary program structure-shy functionality Chapter 1 structure Chapter 2 avoid tangled programs AOP synchronization Chapter 3 Woven meaning of book 4/10/2019 CSU 670/1
crosscutting concerns public class Shape implements ShapeI { protected AdjustableLocation loc; protected AdjustableDimension dim; public Shape() { loc = new AdjustableLocation(0, 0); dim = new AdjustableDimension(0, 0); } double get_x() throws RemoteException { return loc.x(); } void set_x(int x) throws RemoteException { loc.set_x(); } double get_y() throws RemoteException { return loc.y(); } void set_y(int y) throws RemoteException { loc.set_y(); } double get_width() throws RemoteException { return dim.width(); } void set_width(int w) throws RemoteException { dim.set_w(); } double get_height() throws RemoteException { return dim.height(); } void set_height(int h) throws RemoteException { dim.set_h(); } void adjustLocation() throws RemoteException { loc.adjust(); void adjustDimensions() throws RemoteException { dim.adjust(); class AdjustableLocation { protected double x_, y_; public AdjustableLocation(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_ = longCalculation1(); y_ = longCalculation2(); class AdjustableDimension { protected double width_=0.0, height_=0.0; public AdjustableDimension(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;} width_ = longCalculation3(); height_ = longCalculation4(); interface ShapeI extends Remote { double get_x() throws RemoteException ; void set_x(int x) throws RemoteException ; double get_y() throws RemoteException ; void set_y(int y) throws RemoteException ; double get_width() throws RemoteException ; void set_width(int w) throws RemoteException ; double get_height() throws RemoteException ; void set_height(int h) throws RemoteException ; void adjustLocation() throws RemoteException ; void adjustDimensions() throws RemoteException ; Modularization of crosscutting concerns public class Shape { protected double x_= 0.0, y_= 0.0; protected double width_=0.0, height_=0.0; 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 adjustLocation() { x_ = longCalculation1(); y_ = longCalculation2(); } void adjustDimensions() { width_ = longCalculation3(); height_ = longCalculation4(); coordinator Shape { selfex adjustLocation, adjustDimensions; mutex {adjustLocation, get_x, set_x, get_y, set_y}; mutex {adjustDimensions, 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 adjustLocation() {}; void adjustDimensions() {}; Write this Instead of writing this 4/10/2019 CSU 670/1
UML Class Diagram busStops BusRoute BusStopList buses 0..* BusStop BusList Example for developing strategies and writing adaptive programs waiting 0..* passengers Bus PersonList Person 0..* 4/10/2019 CSU 670/1
Collaborating Classes use connectivity in class graph to define them succinctly using strategy graphs separating structure from behavior teasing out the structure aspect from Customer to Agent from Company to Employee 4/10/2019 CSU 670/1
What's the problem? TANGLING OOAD Z customer service center teller service self-service collaborations Collab-1 requirements: use-cases C1 C4 C2 C3 C5 Collab-4 Collab-2 Collab-3 Object-oriented languages do not provide adequate constructs to capture collaborations between several classes. Has been recognized in different forms in the object-oriented community: OO accommodates the addition of new variants of data types better than procedural programming but, the opposite is true when new operations on existing data types are needed visitor pattern: the matter of concern -- definition of new operations on an existing object structure (aggregation is involved besides inheritance) several works complain the lack of constructs for expressing collaboration-based designs C1 C4 C2 C3 Implementation C5 classes Collaboration -- a distinct (relatively independent aspect of an application that involves several participants, or roles roles played by application classes each class may play different roles in different collaborations each role embodies a separate aspect of the overall class behavior 4/10/2019 CSU 670/1 Collaboration-based design s Require to view oo applications in two different ways: (a) in terms of participants or types involved (b) in terms of the tasks or concerns of the design
Problems with Object Decomposition in den vorherigen Kapiteln wurde erklärt: 1. in der Informatik darum, Rechnermodelle zu bauen, die Prozessen in der reellen Welt simulieren. 2. Es gibt formale Mitteln, die es erlauben, die Modelle in eine für den Rechner verständlich en Sprache zu schreiben.t. In dieser Vorlesung erden wir das sogenannte objekt-orientierte Programmiermodel als das Mittel für die Beschreibung der Modelle benutzen. Mit anderen Worten, werden wir objekt-orientierte Rechnermodelle der reellen Welt bauen. Wir werden zuerst, die Konstrukte des objekt-orientierten Programmiermodels kennenlernen, d.h. die Bestandteile unsere Toolboxes. Als zweites werden wir kurz During implementation separate higher-level functions are mixed together During maintenance/evolution individual collaborations need to be factored out of the tangled code
Collaborating Classes find all persons waiting at any bus stop on a bus route busStops BusRoute BusStopList OO solution: one method for each red class buses 0..* BusStop BusList waiting 0..* passengers Bus PersonList Person 0..* 4/10/2019 CSU 670/1
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. 4/10/2019 CSU 670/1
find all persons waiting at any bus stop on a bus route Traversal Strategy first try: from BusRoute to Person busStops BusRoute BusStopList buses 0..* BusStop BusList waiting 0..* passengers Bus PersonList Person 0..* 4/10/2019 CSU 670/1
find all persons waiting at any bus stop on a bus route Traversal Strategy from BusRoute through BusStop to Person busStops BusRoute BusStopList buses 0..* BusStop BusList waiting 0..* passengers Bus PersonList Person 0..* 4/10/2019 CSU 670/1
find all persons waiting at any bus stop on a bus route Traversal Strategy Altern.: from BusRoute bypassing Bus to Person busStops BusRoute BusStopList buses 0..* BusStop BusList waiting 0..* passengers Bus PersonList Person 0..* 4/10/2019 CSU 670/1
Robustness of Strategy find all persons waiting at any bus stop on a bus route Robustness of Strategy from BusRoute through BusStop to Person villages BusRoute BusStopList busses VillageList busStops 0..* 0..* BusStop BusList Village waiting 0..* passengers Bus PersonList Person 0..* 4/10/2019 CSU 670/1
TPP: Tip 53: Abstractions Live Longer than Details Is in the Requirements Pit section Also applies to code: don’t overspecify! 4/10/2019 CSU 670/1
Writing Adaptive Programs with Strategies (DJ=pure Java) String WPS=“from BusRoute through BusStop to Person” class BusRoute { int countPersons(ClassGraph cg) { String WPS=“from BusRoute through BusStop 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 getReturnValue() {return new Integer ( r);} }); return result.intValue();} } can we really program with strategies? Here is how. 4/10/2019 CSU 670/1
Writing Adaptive Programs with Strategies (DJ=pure Java) // Prepare the class graph ClassGraph classGraph = new ClassGraph(); int r = aBusRoute.countPersons(classGraph); can we really program with strategies? Here is how. 4/10/2019 CSU 670/1
TPP section: The Evils of Duplication Tip 11: DRY – Don’t Repeat Yourself Imposed duplication without tool support 4/10/2019 CSU 670/1
Cross-cutting in DemeterJ generated Java program DemeterJ program structure-shy functionality structure replicated! aspect descriptions are not just copied into programs, they may be replicated several times. synchronization 4/10/2019 CSU 670/1
Back to COM 1350 A context-free grammar is a 4-tuple (V,Sigma,R,S) V : Variables (or non terminals) Sigma: terminals R : rules S : start variable 4/10/2019 CSU 670/1