5ccf9d0d993ff50ea3a0c88590378b19.ppt
- Количество слайдов: 36
CRC – What is it? 1 Class 1 Responsibilities 1 Collaborations
CRC – What is it? 1 Classes - a group of objects with similar attributes and methods - DOGS 1 Object - an instance of a class - SPOT 1 Attributes - facts belong to an object SPOT is brown, short hair 1 Relationships - an association between objects - SPOT to OWNER
CRC – What is it? 1 Collaboration – Request a service from another object to fulfill a responsibility Contract client server
CRC – Phase 1 1 Find the Objects F Model the domain F What must the system accomplish? F What behavior is clearly outside the system? F For each goal, what kinds of objects are needed to accomplish it?
CRC – Phase 2 1 Determine their Responsibilities F What does each object have to know in order to accomplish each goal it is involved with? F What steps towards accomplishing each goal is it responsible for?
CRC – Phase 3 1 Determine Collaborations F With whom will each object collaborate in order to accomplish each of its responsibilities? F What other objects in the system hold knowledge it needs, or know how to perform some operation it requires? F What is the exact nature of the collaborations between the objects?
CRC – Summary 1 Objects become clients and servers within a system 1 Responsibilities become contracts between them 1 Collaborations are a way of determining which clients and which servers are bound by which contracts
CRC – Walk-through 1 Goal FFor a given network, print different kinds of files (Text File, Formatted File, Graphics File) to different kinds of printers (Dot Matrix Printer, Laser Printer)
CRC – Walk-through print : File 1: print. Request(printer) : Print Server user 4: print(file) 5: get. Contents() 2: add(file) 3: [printer available]get. Next. File() : Printer 6: print. Contents() : Queue
CRC – Walk-through 1 Classes F File and subclasses Text File, Formatted File, and Graphics File F Printer and subclasses Dot Matrix Printer and Laser Printer F Print Server F Queue
CRC – Walk-through 1 Responsibilities F File è know how to print itself è know how to send contents to Printer F Print Server èknow how to respond to requests to print a file èknow the printers on the network FPrinter èknow how to print the contents of a File èknow its printing status èknow its printing capabilities FQueue è know how to respond to request to add and remove files èknow how many files it contains
CRC – Walk-through 1 Collaborations F To fulfill print itself, File is a client of Print Server F To fulfill print request, Print Server is a client of Queue and a client of Printer F To fulfill print contents, Printer is a client of File
CRC – Finding Classes 1 Use Requirements Specification F No requirement specification? èWrite down goals of design 1 Look for noun phrases F Obvious classes/objects F Obvious nonsense (Discard) F Don’t know? ? ?
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.
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. )
Drawing Editor Example 1 Hand out Drawing Editor Requirements Specification
Drawing Editor Example 1 Hand out Drawing Editor Requirements Specification 1 Find Preliminary Classes F Determine Noun Phrases
Drawing Editor Example List of Preliminary Candidates for Classes drawing editor cursor interactive graphics editor element user current selection drawing control point line text creation tool diagonally opposite corner shape of the cursor ellipse I-beam text position tool character mode of operation mouse button editor text element time corner selection tool region creation tool crosshair drawing element start point stop point line creation tool end point rectangle creation tool rectangle associated corner ellipse creation tool point major radius width of the rectangle minor radius height of the rectangle bounding rectangle
Drawing Editor Example 1. Model physical objects Mouse button – Probably an attribute of a mouse or an event
Drawing Editor Example List of Preliminary Candidates for Classes drawing editor cursor interactive graphics editor element user current selection drawing control point line text creation tool diagonally opposite corner shape of the cursor ellipse I-beam text position tool character mode of operation mouse button editor text element time corner selection tool region creation tool crosshair drawing element start point stop point line creation tool end point rectangle creation tool rectangle associated corner ellipse creation tool point major radius width of the rectangle minor radius height of the rectangle bounding rectangle
Drawing Editor Example 2. Model conceptual entities 1 Useful entities – line, rectangle, ellipse, text, character, drawing element, drawing 1 Tool – composed of selection tool & creation tool (four kinds of creation tool) 1 Current selection – user manipulates it 1 Point, Start point, end point, corner (different kinds), major and minor radius, height & width of rectangle, bounding rectangle? ? ?
Drawing Editor Example 3. One word for One concept 1 Drawing editor, interactive graphics editor, or just editor? 1 Drawing element or element? 1 Text or Text Element? F Append Element to line, rectangle, & ellipse.
Drawing Editor Example List of Preliminary Candidates for Classes drawing editor cursor interactive graphics editor element user current selection drawing control point line element text creation tool diagonally opposite corner shape of the cursor ellipse element I-beam text position tool character mode of operation mouse button editor text element time corner selection tool region creation tool crosshair drawing element start point stop point line creation tool end point rectangle creation tool rectangle element associated corner ellipse creation tool point major radius width of the rectangle minor radius height of the rectangle bounding rectangle
Drawing Editor Example 4. Watch out for adjectives 1 Do selection tool and the various creation tools behave differently? 1 Rectangle, Bounding Rectangle, Region? 1 Point, stop point, end point, control point? 1 Corner, diagonally opposite corner, associated corner?
Drawing Editor Example List of Preliminary Candidates for Classes drawing editor cursor interactive graphics editor element user current selection drawing control point line element text creation tool diagonally opposite corner shape of the cursor ellipse element I-beam text position tool character mode of operation mouse button editor text element time corner selection tool region creation tool crosshair drawing element start point stop point line creation tool end point rectangle creation tool rectangle element associated corner ellipse creation tool point major radius width of the rectangle minor radius height of the rectangle bounding rectangle
Drawing Editor Example 5. Watch out for sentences with no clear subject 1 “The current selection is indicated visually by displaying the control points for the element” F Who is displaying the control points for the current selection? 1 “…the user can create an element of the selected kind. ” F Creation tool classes can be regarded as stand-ins for the user
Drawing Editor Example 6. Model Categories 1 Tool and Creation Tools 1 Drawing Element
Drawing Editor Example 7. Model Interfaces 1 User? 1 User Interface? Yes-part of design phase 1 Cursor? 1 Time?
Drawing Editor Example List of Preliminary Candidates for Classes drawing editor cursor interactive graphics editor element user current selection drawing control point line element text creation tool diagonally opposite corner shape of the cursor ellipse element I-beam text position tool character mode of operation mouse button editor text element time corner selection tool region creation tool crosshair drawing element start point stop point line creation tool end point rectangle creation tool rectangle element associated corner ellipse creation tool point major radius width of the rectangle minor radius height of the rectangle bounding rectangle
Drawing Editor Example 8. Model values of attributes, not attributes themselves 1 Height of Rectangle, Width of Rectangle? 1 Major radius, minor radius? 1 Position? 1 Mode of Operation? 1 Shape of the cursor? 1 Corner?
Drawing Editor Example List of Preliminary Candidates for Classes drawing editor cursor interactive graphics editor element user current selection drawing control point line element text creation tool diagonally opposite corner shape of the cursor ellipse element I-beam text position tool character mode of operation mouse button editor text element time corner selection tool region creation tool crosshair drawing element start point stop point line creation tool end point rectangle creation tool rectangle element associated corner ellipse creation tool point major radius width of the rectangle minor radius height of the rectangle bounding rectangle
Drawing Editor Example Summary of Remaining Candidate Classes Character Control Point Creation Tool Current Selection Drawing Editor Drawing Element Ellipse Creation Tool Ellipse Element Line Creation Tool Line Element Point Rectangle Creation Tool Rectangle Element Selection Tool Text Creation Tool Text Element Tool
Drawing Editor Example 1 Record candidate classes on CRC card Class: Drawing
Drawing Editor Example 1 Finding Abstract Classes F Determine shared behavior F Look for common attributes F Group related classes
Drawing Editor Example Tool Selection Tool Ellipse Creation Tool Line Creation Tool Rectangle Creation Tool Text Creation Tool
Drawing Editor Example 1 Record superclasses and subclasses Class: Creation Tool Ellipse Tool, Line Tool, Rectangle Tool, Text Tool