Synthetic OO Design Concepts & Reuse Lecture 8: Modeling & documenting collaborations. Topics: Synthesis of multiple collaborations Documenting collaborations with abstract roles A “model” of reuse in role-based designs. New concepts. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Topics:– Synthesis of multiple collaborations– Documenting collaborations with abstract roles– A “model” of reuse in role-based designs
CSE 335: Software Design K. Stirewalt
New conceptsCollaboration: Contextual relationship among
instances that interact to implement a desired functionality– pattern of message exchange among those instances to
achieve some goal– protocol
Role: that subset of an object’s characteristics needed to fulfill its responsibilities in a collaboration– alternatively, a “slot” that can be filled by objects that wish
to participate in the collaboration– such objects are said to “play” the role
Observe: Both definitions refer to instances
Goals:1. Design reusable collaborations2. Compose applications by synthesizing collaborations
CSE 335: Software Design K. Stirewalt
Example
Suppose we want to design a graphical browser that allows users to view and print documents
Two collaborations here:1. A viewPort that displays lines of text, which it
receives by collaborating with a docMgr; and2. A printButton that sends messages to docMgr
to cause it to print.
Observe:– docMgr object is involved in both collaborations– It plays a different role in each
class ViewPort : public public: ViewPort( int x, int y, unsigned numberOfLines
Print
Note: The unseen document manager is serving lines from file “ViewPort.h”
CSE 335: Software Design K. Stirewalt
Motivation: Explaining a designModern OO systems comprise lots of
collaborations
To understand such systems, requires visualizing: – the inter-connection of these objects (i.e.,
structure)– the dynamic interactions among these objects (i.e.,
behavior)
Problem: How can we visualize these phenomena in a useful way?
CSE 335: Software Design K. Stirewalt
Sequence diagrams
Illustrate one instance of one collaboration among multiple objects
Feature:– Use of spatial position to reflect time dimension– Use of vertical bars to denote object “activity”– Graphic denotation of returns from operations
Note: Because it depicts only one instance, a single sequence diagram rarely sufficient to fully document a collaboration
CSE 335: Software Design K. Stirewalt
Example sequence diagram
userEvent()buttonPressed(“Print”)
print : Button docMgr : MyDocManager
sd clickPrint
printDocument()
CSE 335: Software Design K. Stirewalt
Example sequence diagram (continued)
userEvent()buttonPressed(“Print”)
print : Button docMgr : MyDocManager
sd clickPrint
printDocument()
activations
CSE 335: Software Design K. Stirewalt
Example sequence diagram (continued)
userEvent()buttonPressed(“Print”)
print : Button docMgr : MyDocManager
sd clickPrint
printDocument()
messages
CSE 335: Software Design K. Stirewalt
Example sequence diagram (continued)
userEvent()buttonPressed(“Print”)
print : Button docMgr : MyDocManager
sd clickPrint
printDocument()
return messages
CSE 335: Software Design K. Stirewalt
New concept: Role
Defn: A “slot” that can be filled by many different object (or link) instances
Example: The ButtonListener “object” in a design that uses buttons– Not really any such thing as a ButtonListener
“object”– But lots of objects can be “plugged into” that slot.
Design tip: Identification of roles enables the design of reusable collaborations
CSE 335: Software Design K. Stirewalt
Reusable interaction, defined using a role
userEvent()buttonPressed(…)
: Button listener : ButtonListener
sd clickButton
CSE 335: Software Design K. Stirewalt
Instance of an abstract class?
userEvent()buttonPressed(…)
: Button listener : ButtonListener
sd clickButton
Notice: OK to depict what appears to be an “instance” of an abstract class in this situation
class ViewPort : public public: ViewPort( int x, int y, unsigned numberOfLines
Print
Note: The unseen document manager is serving lines from file “ViewPort.h”
CSE 335: Software Design K. Stirewalt
Exercise
Draw a sequence diagram that depicts the interaction between a viewport object (vp) and a DocumentManager object (docMgr) when vp is resized
CSE 335: Software Design K. Stirewalt
Example: Class DocManagerclass DocManager {
public:
…
void printDocument() const;
unsigned docSize() const;
const string& docLine( unsigned ) const;
void insertLine( unsigned, const string& );
void appendLine( const string& );
void deleteLine( unsigned );
};
CSE 335: Software Design K. Stirewalt
Example: Sequence diagram
docMgr : MyDocManagervp : ViewPortresize()
retrieve( 0, .... ) docSize()
docLine(0,...)
update()
retrieve( 1, .... )
docLine(1,...)
retrieve( n-1, .... )
docLine(n-1,...)
docSize()
docSize()
sd resizeView
CSE 335: Software Design K. Stirewalt
Question
Consider the interaction between the document manager and a viewport that displays its contents. Are there any opportunities for role abstraction in this interaction?
CSE 335: Software Design K. Stirewalt
When vp collaborates with a docMgr...
docMgr : MyDocManagervp : ViewPortresize()
retrieve( 0, .... ) docSize()
docLine(0,...)
update()
retrieve( 1, .... )
docLine(1,...)
retrieve( n-1, .... )
docLine(n-1,...)
docSize()
docSize()
sd resizeView
CSE 335: Software Design K. Stirewalt
More general (reusable) interaction using the abstract role “model”
update()
retrieve(n) *
: ViewPort model : ViewPortModel
sd refreshView
CSE 335: Software Design K. Stirewalt
Collaboration diagram
vpm : ViewPortModelvp : ViewPortmodel
ViewPort–ViewPortModel
Example of a collaboration diagram.
CSE 335: Software Design K. Stirewalt
Reusable class ViewPortclass ViewPort : public Fl_Multiline_Output {
public:
ViewPort( int x, int y, int w, int h );
unsigned capacity() const;
void setModel( ViewPortModel* );
protected:
ViewPortModel* model;
void resize(int, int, int, int);
void update();
}; Question: Why is this method protected, rather than public?
CSE 335: Software Design K. Stirewalt
ViewportModel interface
class ViewPortModel {
public:
virtual bool retrieve( unsigned lineNumber,
string& line ) const =0;
};
CSE 335: Software Design K. Stirewalt
Example: ViewPort::Update methodvoid ViewPort::update(){ if (!model) return;
string contents, str;
const string endofline("\n");
for (int i=0; i < upperBound; i++) { if( model->retrieve(i, str) ) {
contents += str; contents += endofline; } }
value(contents.c_str());}
CSE 335: Software Design K. Stirewalt
Example: Synthesis of multiple rolesclass MyDocManager : public DocManager,
Collaboration: Contextual relationship among instances that interact to implement a desired functionality
Collaboration diagram: A diagram describing the structural relationship among the roles in a collaboration
Collaboration role: A “slot” for an object or link within a collaboration. It specifies the kind of object or link that may appear in an instance of the collaboration.
CSE 335: Software Design K. Stirewalt
ScrollBar collaboration
userEvent()announceNewValue(n)
: ScrollBar listener : ValuatorListener
sd moveHandle
CSE 335: Software Design K. Stirewalt
Exercise
Integrate a scrollbar object into our viewport–docManager collaboration. Draw a sequence diagram to illustrate what happens when the user drags the slider handle to a new position.