2So far Behaviour model Structural Model This week Use Case Diagrams Use Case DescriptionsStructural ModelClass DiagramsThis weekContinue with Behavioural ModelClass Responsibility Collaboration Cards
3Background Created by Tektronix, in Portland, Oregon (1989) Large users of SmalltalkAttributed with the development of several key ideas in object technologyWard Cunningham and Kent BeckPresented as a technique to help ‘think objects’NOT part of UML
4Responsibilities and Collaborations KnowingDoingCollaborationObjects working together to service a requestObject oriented systems are made up of objects working together to provide functionalityCRC cards can help to form a “bridge” from structural model to behavioral model
5The essentials of CRC cards AnthropomorphismPretending classes have human characteristicsExtremely simple techniqueRather than use diagrams to develop models use 4 x 6 index cardsRather than indicate attributes and operations on the cards, they identify responsibilities and collaboratorsTwo uses:Examining domainBased upon use cases and use case descriptions from the domain
6CRC Cards Many templates exist (see Dennis for another) On the index card, record the following information:-the name of the class, at the topthe responsibilities of the class, on the left-hand sidethe collaborators of the class, which help to carry out each responsibility, on the right-hand side of the cardMany templates exist (see Dennis for another)
7Example Simple CRC card StudentResponsibilityCollaboratorsComplete AssessmentAssessmentSubmit AssessmentSchool officeAttend LectureLectureAttend SeminarSeminarQuick exercise – What have I missed? What other responsibilities and collaborators are there?
8Exercise 1Consider a public house. Consider two classes in the public house. Think about the working of a pub and the interactions betweenBar personCustomerDraw CRC cards for these two classesThis may involve you identifying other classesThis should take about 10 minutes
9Exercise 1 – One Possible Answer Bar PersonResponsibilityCollaboratorsTake orders from customersOrderCustomerServe ordersProductTake payments and give changeTillCheck stockStock
10Exercise 1 – One Possible Answer CustomerResponsibilityCollaboratorsGiven ordersBar PersonOrderReceive ordersProductMake payments
11What have we seen Identification of “new” classes OrderProductTillStockHow classes interact to provide functionalityA feel for behavioural aspects of the systemEach of these would also need a CRC card
12CRC Card Responsibilities The responsibilities of the class describe at a high-level the purpose of the class’s existenceThey are connected to the operations the class provides, but are more general than that might imply :e.g. in a library system “Make Payment” is acceptable as a description of a responsibilitythere may well be many associated operations
13Coupling & Cohesion A criteria for Good Analysis / Design Coupling Degree of InterconnectednessNumber of links & degree of interactionCohesionContribution to single purposeNot mutually exclusiveYou should note that Coupling and Cohesion are among the criteria for defining good analysis / design, in fact it is good practice (during the analysis phase) to prepare models that satisfy these criteria. Coupling describes the degree of interconnectedness between design components and is reflected by the number of links an object has and by the degree of interaction the object has with other objects. Cohesion is a measure of the degree to which an element contributes to a single purpose. Coupling consists of Interaction coupling and Inheritance coupling, but more on this later. While cohesion consists of Operation cohesion, Class cohesion and Specialisation cohesion, again but more on this later. You should be aware that the concepts of coupling and cohesion are not mutually exclusive but actually support each other.
14CRC Good Practice If a class has lots of responsibilities :- Can describe them more concisely, and, if notWould be better to split the responsibilities and have two or more classesToo many responsibilities:Bad- low cohesionToo many collaborators:Bad -high couplingUsing CRC cards should help to identify and fix both these faults in a model
15Why use CRC cardsAt the start, you may not know which other classes a class has to collaborate with in order to fulfill a responsibilityUsing CRC cards facilitate thisIf an object of one class collaborates with an object of another class, it does so by using operations of the otherA class has a relationship with each of it’s collaboratorsUsing CRC cards is helps to establish in which direction associations should be navigable
16Class Diagrams – navigable relationships So far all relationships in class diagrams and use cases have been navigable in two waysThis is not always the caseOfficer is investigating a crimeCrime doesn’t know which officer is investigating it or indeed if it is being investigated!
17CRC cards in practice (1 of 2) One of the main benefits of CRC cards is that they encourage animated discussion among developersEspecially effective when walking through a Use Case to see how the classes are going to implement it (using role play)We will see an example of this in the seminarsAnthropomorphismDevelopers pick cards as each class collaborates in the Use CaseAs ideas about responsibilities are formed the cards are annotated
18CRC cards in practice (2 of 2) Stops thinking about classes as dumb data holders and moves thinking towards understanding the higher-level behavior of each classCRC cards work on ‘object’ communication (not classes)Can provide a draft class modelApart from the technical benefits, stimulatesTeam discussion and hence team spiritTechnique suitable for highlighting opportunities to refactor the class modelRefactoring is the process of altering the class model of an object-oriented design without altering it’s visible behavior
19Exercise 2 – Have another go Consider a Library. A library has Borrowers, Books Copies of Books and Reservations. Borrowers can borrow copies of books and make reservations.Draw CRC cards for the libraryHint classes:BorrowerBookCopyReservation
20Exercise 2 – One possible answer BorrowerResponsibilityCollaboratorsBorrows booksBookCopyReturn booksMake reservationsReservation
21Exercise 2 – One possible answer BookResponsibilityCollaboratorsTo have copiesCopyTo be borrowedBorrowerTo be reservedReservation
22Exercise 2 – One possible answer CopyResponsibilityCollaboratorsProvides book infoBookProvides borrower infoBorrowerProvides reservation infoReservation
23Exercise 2 – One possible answer ReservationResponsibilityCollaboratorsTo create a reservation for a bookBookBorrowerTo hold copyCopy
24This weeks reading ESSENTIAL READING Dennis A, Wixom B, and Tegarden D (2005) System Analysis and Design with UML version 2 second edition, WileyChapter 7 ( especially )Further readingBennett, S., McRobb, S. and Farmer, R. (2002) Object-Oriented Systems Analysis and Design using UML, 2nd Edition, McGraw-HillPages