K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 7: Roles and Collaborations Topics: – Interactive applications, their.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Containers CMPS Reusable containers Simple data structures in almost all nontrivial programs Examples: vectors, linked lists, stacks, queues, binary.
UML an overview.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Object Oriented Programming Lecture 7: Algorithm animation using strategy and factory patterns, The Adapter design pattern
Introduction To System Analysis and Design
What is an object? Your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior;
Software Testing and Quality Assurance
K. Stirewalt CSE 335: Software Design Foundations: Language Mechanisms and Primitive OO Concepts Lecture 2: Polymorphism Topics: – Polymorphism and virtual.
E. Kraemer CSE 335: Software Design Administrivia Exam 2 : Wednesday, March pm Room: TBA Wed, March 12th - exam outline in class Mon, March 17th.
K. Stirewalt CSE 335: Software Design Outline of course topics Foundational OO concepts Synthetic concepts: –Program families, program fragments, and abstract.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 9: Collaboration synthesis Topics: –Composition of existing collaborations.
K. Stirewalt CSE 335: Software Design Software Architecture and Larger System Design Issues Lecture 3: Synchronization Topics: –Concurrent access to shared.
K. Stirewalt CSE 335: Software Design Software architecture and larger system design issues Lecture 1: Simulating concurrency Topics: –High-level software.
K. Stirewalt CSE 335: Software Design Software Architecture and Larger System Design Issues Lecture 4: Life cycles of concurrent actors Topics: –The “life.
C++ fundamentals.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CSE 332: C++ Classes From Procedural to Object-oriented Programming Procedural programming –Functions have been the main focus so far Function parameters.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
Ranga Rodrigo. Class is central to object oriented programming.
Introduction To System Analysis and design
Object Oriented Software Development
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Design Patterns.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Introduction To System Analysis and Design
Abstract Factory Design Pattern making abstract things.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Programming in C# Observer Design Pattern
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Generic abstraction  Genericity  Generic classes  Generic procedures Programming Languages 3 © 2012 David A Watt, University of Glasgow.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Information System Design (IT60105) Lecture 26 Object-Oriented System Testing.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 8: Modeling & documenting collaborations Topics: –Synthesis of multiple.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
OBSERVER DESIGN PATTERN. Behavioral Patterns  Behavioral patterns are those patterns that are most specifically concerned with communication between.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
Foundations: Language mechanisms and primitive OO concepts Lecture 1: Classification and Inheritance Michigan State University Spring 2008 E. Kraemer Notes.
K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 5: Mixins and reusable strategies Topics: – More on the use of mixins.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Ying Huang, Marc Sentany Department of Computer Science.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Exam Review 2 Chapter 5 – 9 CSC212 FG CS Dept, CCNY.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Design and implementation Chapter 7 – Lecture 1. Design and implementation Software design and implementation is the stage in the software engineering.
CSCI 383 Object-Oriented Programming & Design Lecture 7 Martin van Bommel.
Object Oriented Analysis & Design By Rashid Mahmood.
Programming Paradigms, Software Architectural Patterns, and MVC CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
CompSci 230 S Programming Techniques
CompSci 280 S Introduction to Software Development
Object-Oriented Programming Concepts
Programming & Scratch.
Understand the Fundamentals of Classes
Object-Oriented Analysis and Design
7. Inheritance and Polymorphism
A Brief Introduction to Design Patterns
Observer Design Pattern
Programming in Java Event Handling
Behavioral Design Pattern
Software Design Lecture : 15.
Presentation transcript:

K. Stirewalt CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 7: Roles and Collaborations Topics: – Interactive applications, their design and behavior – The Button–ButtonListener collaboration – Brief introduction to the fltk user-interface toolkit library – New design concepts: Roles and collaborations

K. Stirewalt CSE 335: Software Design Recall from last time… Reusable classes with dynamic behavior –Example: Class Button –Issue: How to design Button w/o knowing class of objects that are to receive “button pressed” messages –Solution: Invented an interface class that declares nothing but a buttonPressed operation Designed class Button with respect to this interface class Requires: –Receiver classes to implement the interface –Receiver objects (targets) register with the Button object

K. Stirewalt CSE 335: Software Design Adapter class in running example class MyDocManager : public DocManager, public ButtonListener { public: void buttonPressed( const string& s ) { if(s == “ print ” ) DocManager::printDocument(); } }; Button > ButtonListener DocManager MyDocManager target

K. Stirewalt CSE 335: Software Design Configuration code int main(void) { Button p( “ print ” ); MyDocManager dm( … ); printButton.addListener(&dm); … return FL::run(); // GUI-toolkit event loop }

K. Stirewalt CSE 335: Software Design Qualities of our design Class Button very reusable We can understand the Button — ButtonListener collaboration with little knowledge of Button and no knowledge of the class of the target object –Example of separation of concerns Clear mechanism for adapting arbitrary class to implement the ButtonListener interface

K. Stirewalt CSE 335: Software Design Interactive applications Behave differently than programs that “compute a function” –Long running; may not terminate –Characterized by long periods of relative inactivity followed by short bursts of behavior Structured differently too: –Procedural code is either: configuration code, or collaboration code –Inversion of control: Methods in objects are “called back” by a central dispatcher which monitors user events

K. Stirewalt CSE 335: Software Design Example using fltk toolkit int main(void) { … Button p( “ print ” ); MyDocManager dm( … ); p.addListener(&dm); … return FL::run(); // GUI-toolkit event loop }

K. Stirewalt CSE 335: Software Design At end of “configuration phase” p : Buttondm : MyDocManager Event Queue Operating system Application target Mouse main

K. Stirewalt CSE 335: Software Design Entering “collaboration phase” p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Step 1.1: App checks event queue p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Step 1.2: App blocks on empty queue p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design User then clicks mouse over p p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Step 1.3: application “wakes” when event arrives p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse leftPress main

K. Stirewalt CSE 335: Software Design Step 1.4: app “pulls” event off queue p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Step 2.1: app “dispatches” event to p p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse p.pressEvent() main

K. Stirewalt CSE 335: Software Design Step 2.2: p notifies dm it was pressed p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse target->buttonPressed( “print” ) main

K. Stirewalt CSE 335: Software Design Step 2.3: dm prints doc and returns p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Step 2.3: dm prints doc and returns p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Step 2.3: dm prints doc and returns p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Step 2.3: dm prints doc and returns p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Repeat Step 1.1: App checks event queue... p : Buttondm : MyDocManager Event Queue Operating system Application target FL::run() Mouse main

K. Stirewalt CSE 335: Software Design Exercise 10.0 Reset Apply Button–ButtonListener collaboration to build an application that allows users to “reset” a graphical slider that selects integer values

K. Stirewalt CSE 335: Software Design Class IvalSlider class IvalSlider : public Fl_Value_Slider { public: IvalSlider( unsigned lb, unsigned ub ); bool valueChanged() const; unsigned getValue(); void resetValue(); private: bool modified; void setValue(unsigned); static void sliderCallback(Fl_Widget*); };

K. Stirewalt CSE 335: Software Design Solution class MyIvalSlider : public ButtonListener, public IvalSlider { public: MyIvalSlider(unsigned l, unsigned u) : IvalSlider(l, u) {} void buttonPressed( const string& label ) { if (label == “ Reset") resetValue(); } };

K. Stirewalt CSE 335: Software Design Configuration code int main(void) { ContainerWindow myContainer(500,150); MyIvalSlider myIval(10, 50); Button myButton(200, 80, "reset"); myButton.setListener(&myIval); myContainer.end(); myContainer.show(); return(Fl::run()); }

K. Stirewalt CSE 335: Software Design Exercise Class IvalSlider cannot notify listeners when its value changes. Design an interface class IvalListener and modify the code for IvalSlider so that: 1.IvalListener objects may register for notification, and 2.IvalSlider objects will notify all registered listeners when the value changes

K. Stirewalt CSE 335: Software Design Solution (elided) class IvalListener { public: virtual void announceNewValue( unsigned ) =0; }; class IvalSlider : public Fl_Value_Slider { public:... void registerListener( IvalListener* l ) { listeners.push_back(l); }... protected: vector listeners; };

K. Stirewalt CSE 335: Software Design Solution (continued) typedef vector ::const_iterator iter; void IvalSlider::setValue( unsigned v ) { modified = true; for ( iter li = listeners.begin(); li != listeners.end(); li++ ) { (*li)->announceNewValue(v); }

K. Stirewalt CSE 335: Software Design Abstraction Defn: Process by which we identify the important aspects of a phenomenon and ignore its details Example: –STL class vector vs bounded sequence –The latter is an abstraction of the former Two popular methods for abstraction over objects: –Classes: groups set of objects with same characteristics –Roles/collaborations: groups set of sets of objects that collaborate by sending messages back and forth to accomplish some goal

K. Stirewalt CSE 335: Software Design Collaboration Defn : Cohesive pattern of interaction (i.e., message exchange) among multiple objects to accomplish some goal or purpose or implement some invariant [VanHilst & Notkin OOPSLA’96] Examples: –Message exchange betw printButton and docMgr –printButton sends buttonPressed message to docMgr Note: Refers to set of objects, not classes

K. Stirewalt CSE 335: Software Design Role Defn : Abstraction of an object in a particular collaboration –Defines only that subset of the object’s characteristics that are meaningful to the collaboration Thus, each object might play many different roles, one for each collaboration in which it is involved; and A given role could be played by many different kinds of objects Example: docMgr object might: –play the ButtonListener role with printButton object –play the IvalListener role with myIval object Roles allow to easily reuse collaborations

K. Stirewalt CSE 335: Software Design Role declarations In C++, we can declare a role using an interface class Examples: class ButtonListener { public: virtual void buttonPressed( const string& )=0; }; class IvalListener { public: virtual void announceNewValue( unsigned )=0; };

K. Stirewalt CSE 335: Software Design Collaboration synthesis Role-based designs simplify the construction of new collaborations, a process known as synthesis Each object in a running program might play a role in multiple collaborations –If object O must play roles { R 1, R 2, … R n } then: –The class of object O must implement the interfaces that specify these roles Application construction in this paradigm involves: –Identifying the collaborations required to accomplish system goals –Synthesizing custom classes to declare objects that play roles in these collaborations