Presentation is loading. Please wait.

Presentation is loading. Please wait.

CRC – What is it?  Class  Responsibilities  Collaborations.

Similar presentations


Presentation on theme: "CRC – What is it?  Class  Responsibilities  Collaborations."— Presentation transcript:

1 CRC – What is it?  Class  Responsibilities  Collaborations

2 CRC – What is it?  Classes - a group of objects with similar attributes and methods - DOGS  Object - an instance of a class - SPOT  Attributes - facts belong to an object - SPOT is brown, short hair  Relationships - an association between objects - SPOT to OWNER

3 CRC – What is it?  Collaboration – Request a service from another object to fulfill a responsibility clientserver Contract

4 CRC – Phase 1  Find the Objects  Model the domain  What must the system accomplish?  What behavior is clearly outside the system?  For each goal, what kinds of objects are needed to accomplish it?

5 CRC – Phase 2  Determine their Responsibilities  What does each object have to know in order to accomplish each goal it is involved with?  What steps towards accomplishing each goal is it responsible for?

6 CRC – Phase 3  Determine Collaborations  With whom will each object collaborate in order to accomplish each of its responsibilities?  What other objects in the system hold knowledge it needs, or know how to perform some operation it requires?  What is the exact nature of the collaborations between the objects?

7 CRC – Summary  Objects become clients and servers within a system  Responsibilities become contracts between them  Collaborations are a way of determining which clients and which servers are bound by which contracts

8 CRC – Walk-through  Goal  For a given network, print different kinds of files (Text File, Formatted File, Graphics File) to different kinds of printers (Dot Matrix Printer, Laser Printer)

9 CRC – Walk-through user :File print :Print Server :Queue :Printer 1:printRequest(printer) 2:add(file) 3:[printer available]getNextFile() 4:print(file) 5:getContents() 6:printContents()

10 CRC – Walk-through  Classes  File and subclasses Text File, Formatted File, and Graphics File  Printer and subclasses Dot Matrix Printer and Laser Printer  Print Server  Queue

11 CRC – Walk-through  Responsibilities  File  know how to print itself  know how to send contents to Printer  Print Server  know how to respond to requests to print a file  know the printers on the network  Printer  know how to print the contents of a File  know its printing status  know its printing capabilities  Queue  know how to respond to request to add and remove files  know how many files it contains

12 CRC – Walk-through  Collaborations  To fulfill print itself, File is a client of Print Server  To fulfill print request, Print Server is a client of Queue and a client of Printer  To fulfill print contents, Printer is a client of File

13 CRC – Finding Classes  Use Requirements Specification  No requirement specification?  Write down goals of design  Look for noun phrases  Obvious classes/objects  Obvious nonsense (Discard)  Don’t know???

14 CRC – Finding Classes - Guidelines 1.Model physical objects Disks, printers 2.Model conceptual entities Windows, Files 3.If more than one word is used for the same concept, choose the one that is most meaningful in terms of the rest of the system. 4.Be wary of the use of adjectives. If the use of the adjective in conjunction with the noun implies different object behavior, then make a new class.

15 CRC – Finding Classes - Guidelines 5.Be wary of sentences in the passive voice, or those whose subjects are not part of the system. 6.Model categories of classes. (Could be abstract superclasses.) 7.Model known interfaces to the outside world. User Interface 8.Model the values of attributes of objects, not the attributes. (Float, Wheel, etc.)

16 Drawing Editor Example  Hand out Drawing Editor Requirements Specification

17 Drawing Editor Example  Hand out Drawing Editor Requirements Specification  Find Preliminary Classes  Determine Noun Phrases

18 Drawing Editor Example List of Preliminary Candidates for Classes drawing editorcursorstop point interactive graphics editorelementline creation tool usercurrent selectionend point drawingcontrol pointrectangle creation tool linetext creation toolrectangle diagonally opposite cornershape of the cursorassociated corner ellipseI-beamellipse creation tool textpositionpoint toolcharactermajor radius mode of operationmouse buttonwidth of the rectangle editortext elementminor radius timecornerheight of the rectangle selection toolregionbounding rectangle creation toolcrosshair drawing elementstart point

19 Drawing Editor Example 1. Model physical objects Mouse button – Probably an attribute of a mouse or an event

20 Drawing Editor Example List of Preliminary Candidates for Classes drawing editorcursorstop point interactive graphics editorelementline creation tool usercurrent selectionend point drawingcontrol pointrectangle creation tool linetext creation toolrectangle diagonally opposite cornershape of the cursorassociated corner ellipseI-beamellipse creation tool textpositionpoint toolcharactermajor radius mode of operationmouse buttonwidth of the rectangle editortext elementminor radius timecornerheight of the rectangle selection toolregionbounding rectangle creation toolcrosshair drawing elementstart point

21 Drawing Editor Example 2. Model conceptual entities  Useful entities – line, rectangle, ellipse, text, character, drawing element, drawing  Tool – composed of selection tool & creation tool (four kinds of creation tool)  Current selection – user manipulates it  Point, Start point, end point, corner (different kinds), major and minor radius, height & width of rectangle, bounding rectangle?????

22 Drawing Editor Example 3. One word for One concept  Drawing editor, interactive graphics editor, or just editor?  Drawing element or element?  Text or Text Element?  Append Element to line, rectangle, & ellipse.

23 Drawing Editor Example List of Preliminary Candidates for Classes drawing editorcursorstop point interactive graphics editorelementline creation tool usercurrent selectionend point drawingcontrol pointrectangle creation tool line elementtext creation toolrectangle element diagonally opposite cornershape of the cursorassociated corner ellipse element I-beamellipse creation tool textpositionpoint toolcharactermajor radius mode of operationmouse buttonwidth of the rectangle editortext elementminor radius timecornerheight of the rectangle selection toolregionbounding rectangle creation toolcrosshair drawing elementstart point

24 Drawing Editor Example 4.Watch out for adjectives  Do selection tool and the various creation tools behave differently?  Rectangle, Bounding Rectangle, Region?  Point, stop point, end point, control point?  Corner, diagonally opposite corner, associated corner?

25 Drawing Editor Example List of Preliminary Candidates for Classes drawing editorcursorstop point interactive graphics editorelementline creation tool usercurrent selectionend point drawingcontrol pointrectangle creation tool line elementtext creation toolrectangle element diagonally opposite cornershape of the cursorassociated corner ellipse element I-beamellipse creation tool textpositionpoint toolcharactermajor radius mode of operationmouse buttonwidth of the rectangle editortext elementminor radius timecornerheight of the rectangle selection toolregionbounding rectangle creation toolcrosshair rectangle drawing elementstart point

26 Drawing Editor Example 5.Watch out for sentences with no clear subject  “The current selection is indicated visually by displaying the control points for the element”  Who is displaying the control points for the current selection?  “…the user can create an element of the selected kind.”  Creation tool classes can be regarded as stand-ins for the user

27 Drawing Editor Example 6.Model Categories  Tool and Creation Tools  Drawing Element

28 Drawing Editor Example 7.Model Interfaces  User?  User Interface? Yes-part of design phase  Cursor?  Time?

29 Drawing Editor Example List of Preliminary Candidates for Classes drawing editorcursorstop point interactive graphics editorelementline creation tool usercurrent selectionend point drawingcontrol pointrectangle creation tool line elementtext creation toolrectangle element diagonally opposite cornershape of the cursorassociated corner ellipse element I-beamellipse creation tool textpositionpoint toolcharactermajor radius mode of operationmouse buttonwidth of the rectangle editortext elementminor radius timecornerheight of the rectangle selection toolregionbounding rectangle creation toolcrosshairrectangle drawing elementstart point

30 Drawing Editor Example 8.Model values of attributes, not attributes themselves  Height of Rectangle, Width of Rectangle?  Major radius, minor radius?  Position?  Mode of Operation?  Shape of the cursor?  Corner?

31 Drawing Editor Example List of Preliminary Candidates for Classes drawing editorcursorstop point interactive graphics editorelementline creation tool usercurrent selectionend point drawingcontrol pointrectangle creation tool line elementtext creation toolrectangle element diagonally opposite cornershape of the cursorassociated corner ellipse element I-beamellipse creation tool textpositionpoint toolcharactermajor radius mode of operationmouse buttonwidth of the rectangle editortext elementminor radius timecornerheight of the rectangle selection toolregionbounding rectangle creation toolcrosshairrectangle drawing elementstart point

32 Drawing Editor Example Summary of Remaining Candidate Classes CharacterEllipse Creation ToolRectangle Element Control PointEllipse ElementSelection Tool Creation ToolLine Creation ToolText Creation Tool Current Selection Line ElementText Element DrawingPointTool Drawing EditorRectangle Drawing ElementRectangle Creation Tool

33 Drawing Editor Example  Record candidate classes on CRC card Class: Drawing

34 Drawing Editor Example  Finding Abstract Classes  Determine shared behavior  Look for common attributes  Group related classes

35 Drawing Editor Example Tool Creation Tool Selection Tool Rectangle Creation Tool Line Creation Tool Ellipse Creation Tool Text Creation Tool

36 Drawing Editor Example  Record superclasses and subclasses Class: Creation Tool Tool Ellipse Tool, Line Tool, Rectangle Tool, Text Tool


Download ppt "CRC – What is it?  Class  Responsibilities  Collaborations."

Similar presentations


Ads by Google