1 / 33

Synthetic OO Design Concepts & Reuse Lecture 8: Modeling & documenting collaborations

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.

yaholo
Télécharger la présentation

Synthetic OO Design Concepts & Reuse Lecture 8: Modeling & documenting collaborations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Synthetic OO Design Concepts & ReuseLecture 8: Modeling & documenting collaborations Topics: Synthesis of multiple collaborations Documenting collaborations with abstract roles A “model” of reuse in role-based designs CSE 335: Software Design

  2. New concepts Collaboration: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: • Design reusable collaborations • Compose applications by synthesizing collaborations CSE 335: Software Design

  3. Example Suppose we want to design a graphical browser that allows users to view and print documents Two collaborations here: • A viewPort that displays lines of text, which it receives by collaborating with a docMgr; and • 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 CSE 335: Software Design

  4. #ifndef VIEWPORT_H #define VIEWPORT_H #include <FL/Fl_Multiline #include “ViewPortModel.h class ViewPort : public public: ViewPort( int x, int y, unsigned numberOfLines Print Graphical depiction of example app Note:The unseen document manager is serving lines from file “ViewPort.h” CSE 335: Software Design

  5. Motivation: Explaining a design Modern 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

  6. 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

  7. Example sequence diagram sd clickPrint print : Button docMgr : MyDocManager userEvent() buttonPressed(“Print”) printDocument() CSE 335: Software Design

  8. Example sequence diagram (continued) sd clickPrint print : Button docMgr : MyDocManager userEvent() buttonPressed(“Print”) printDocument() activations CSE 335: Software Design

  9. Example sequence diagram (continued) sd clickPrint print : Button docMgr : MyDocManager userEvent() buttonPressed(“Print”) printDocument() messages CSE 335: Software Design

  10. Example sequence diagram (continued) sd clickPrint print : Button docMgr : MyDocManager userEvent() buttonPressed(“Print”) printDocument() return messages CSE 335: Software Design

  11. 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

  12. Reusable interaction, defined using a role sd clickButton : Button listener : ButtonListener userEvent() buttonPressed(…) CSE 335: Software Design

  13. Instance of an abstract class? sd clickButton : Button listener : ButtonListener userEvent() buttonPressed(…) Notice: OK to depict what appears to be an “instance” of an abstract class in this situation CSE 335: Software Design

  14. listeners Collaboration diagram Button–ButtonListener button : Button listener : ButtonListener [0..*] Example of a collaboration diagram. CSE 335: Software Design

  15. Collaboration diagram Button–ButtonListener role name type role name type multiplicity listeners button : Button listener : ButtonListener [0..*] connector role role Example of a collaboration diagram. CSE 335: Software Design

  16. Collaboration + seq diagrams A reusable collaboration is specified using: • One collaboration diagram that names all of the roles and connectors and specifies any relevant multiplicities • Multiple sequence diagrams, each depicting a “key” behavior among the objects that and links that play roles in the collaboration Such documentation much more useful than “header” comments in the code  CSE 335: Software Design

  17. Another useful collaboration Viewport–ViewPortModel CSE 335: Software Design

  18. #ifndef VIEWPORT_H #define VIEWPORT_H #include <FL/Fl_Multiline #include “ViewPortModel.h class ViewPort : public public: ViewPort( int x, int y, unsigned numberOfLines Print Recall the running example... Note:The unseen document manager is serving lines from file “ViewPort.h” CSE 335: Software Design

  19. 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

  20. Example: Class DocManager class 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

  21. Example: Sequence diagram sd resizeView vp : ViewPort docMgr : MyDocManager resize() update() docSize() retrieve( 0, .... ) docLine(0,...) docSize() retrieve( 1, .... ) docLine(1,...) docSize() retrieve( n-1, .... ) docLine(n-1,...) CSE 335: Software Design

  22. 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

  23. When vp collaborates with a docMgr... sd resizeView vp : ViewPort docMgr : MyDocManager resize() update() docSize() retrieve( 0, .... ) docLine(0,...) docSize() retrieve( 1, .... ) docLine(1,...) docSize() retrieve( n-1, .... ) docLine(n-1,...) CSE 335: Software Design

  24. More general (reusable) interaction using the abstract role “model” sd refreshView : ViewPort model : ViewPortModel update() retrieve(n) * CSE 335: Software Design

  25. model Collaboration diagram ViewPort–ViewPortModel vp : ViewPort vpm : ViewPortModel Example of a collaboration diagram. CSE 335: Software Design

  26. Reusable class ViewPort class 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

  27. ViewportModel interface class ViewPortModel { public: virtual bool retrieve( unsigned lineNumber, string& line ) const =0; }; CSE 335: Software Design

  28. Example: ViewPort::Update method void 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

  29. Example: Synthesis of multiple roles class MyDocManager : public DocManager, public ButtonListener, public ViewPortModel { public: void buttonPressed( const string& s ) { if(s == “print”) DocManager::printDocument(); } bool retrieve( unsigned lineNo, string& line ) const { bool retVal = (lineNo < DocManager::docSize()); if (retVal) line = DocManager::docLine(lineNo); return retVal; } }; CSE 335: Software Design

  30. Configuration code int main(void) { ContainerWindow myContainer(500,150); MyDocManager docMgr(...); Button printButton(200, 80, “Print"); ViewPort viewPort(0,0, 350, 120); printButton.addListener(&docMgr); viewPort.setModel(&docMgr); myContainer.end(); myContainer.show(); return Fl::run(); } CSE 335: Software Design

  31. Terminology 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

  32. ScrollBar collaboration sd moveHandle : ScrollBar listener : ValuatorListener userEvent() announceNewValue(n) CSE 335: Software Design

  33. 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. CSE 335: Software Design

More Related