Presentation is loading. Please wait.

Presentation is loading. Please wait.

IS514 Lecture Week 9 CRC Cards.

Similar presentations


Presentation on theme: "IS514 Lecture Week 9 CRC Cards."— Presentation transcript:

1 IS514 Lecture Week 9 CRC Cards

2 So far Behaviour model Structural Model This week Use Case Diagrams
Use Case Descriptions Structural Model Class Diagrams This week Continue with Behavioural Model Class Responsibility Collaboration Cards

3 Background Created by Tektronix, in Portland, Oregon (1989)
Large users of Smalltalk Attributed with the development of several key ideas in object technology Ward Cunningham and Kent Beck Presented as a technique to help ‘think objects’ NOT part of UML

4 Responsibilities and Collaborations
Knowing Doing Collaboration Objects working together to service a request Object oriented systems are made up of objects working together to provide functionality CRC cards can help to form a “bridge” from structural model to behavioral model

5 The essentials of CRC cards
Anthropomorphism Pretending classes have human characteristics Extremely simple technique Rather than use diagrams to develop models use 4 x 6 index cards Rather than indicate attributes and operations on the cards, they identify responsibilities and collaborators Two uses: Examining domain Based upon use cases and use case descriptions from the domain

6 CRC Cards Many templates exist (see Dennis for another)
On the index card, record the following information:- the name of the class, at the top the responsibilities of the class, on the left-hand side the collaborators of the class, which help to carry out each responsibility, on the right-hand side of the card Many templates exist (see Dennis for another)

7 Example Simple CRC card
Student Responsibility Collaborators Complete Assessment Assessment Submit Assessment School office Attend Lecture Lecture Attend Seminar Seminar Quick exercise – What have I missed? What other responsibilities and collaborators are there?

8 Exercise 1 Consider a public house. Consider two classes in the public house. Think about the working of a pub and the interactions between Bar person Customer Draw CRC cards for these two classes This may involve you identifying other classes This should take about 10 minutes

9 Exercise 1 – One Possible Answer
Bar Person Responsibility Collaborators Take orders from customers Order Customer Serve orders Product Take payments and give change Till Check stock Stock

10 Exercise 1 – One Possible Answer
Customer Responsibility Collaborators Given orders Bar Person Order Receive orders Product Make payments

11 What have we seen Identification of “new” classes
Order Product Till Stock How classes interact to provide functionality A feel for behavioural aspects of the system Each of these would also need a CRC card

12 CRC Card Responsibilities
The responsibilities of the class describe at a high-level the purpose of the class’s existence They 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 responsibility there may well be many associated operations

13 Coupling & Cohesion A criteria for Good Analysis / Design Coupling
Degree of Interconnectedness Number of links & degree of interaction Cohesion Contribution to single purpose Not mutually exclusive You 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.

14 CRC Good Practice If a class has lots of responsibilities :-
Can describe them more concisely, and, if not Would be better to split the responsibilities and have two or more classes Too many responsibilities: Bad- low cohesion Too many collaborators: Bad -high coupling Using CRC cards should help to identify and fix both these faults in a model

15 Why use CRC cards At the start, you may not know which other classes a class has to collaborate with in order to fulfill a responsibility Using CRC cards facilitate this If an object of one class collaborates with an object of another class, it does so by using operations of the other A class has a relationship with each of it’s collaborators Using CRC cards is helps to establish in which direction associations should be navigable

16 Class Diagrams – navigable relationships
So far all relationships in class diagrams and use cases have been navigable in two ways This is not always the case Officer is investigating a crime Crime doesn’t know which officer is investigating it or indeed if it is being investigated!

17 CRC cards in practice (1 of 2)
One of the main benefits of CRC cards is that they encourage animated discussion among developers Especially 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 seminars Anthropomorphism Developers pick cards as each class collaborates in the Use Case As ideas about responsibilities are formed the cards are annotated

18 CRC 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 class CRC cards work on ‘object’ communication (not classes) Can provide a draft class model Apart from the technical benefits, stimulates Team discussion and hence team spirit Technique suitable for highlighting opportunities to refactor the class model Refactoring is the process of altering the class model of an object-oriented design without altering it’s visible behavior

19 Exercise 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 library Hint classes: Borrower Book Copy Reservation

20 Exercise 2 – One possible answer
Borrower Responsibility Collaborators Borrows books Book Copy Return books Make reservations Reservation

21 Exercise 2 – One possible answer
Book Responsibility Collaborators To have copies Copy To be borrowed Borrower To be reserved Reservation

22 Exercise 2 – One possible answer
Copy Responsibility Collaborators Provides book info Book Provides borrower info Borrower Provides reservation info Reservation

23 Exercise 2 – One possible answer
Reservation Responsibility Collaborators To create a reservation for a book Book Borrower To hold copy Copy

24 This weeks reading ESSENTIAL READING
Dennis A, Wixom B, and Tegarden D (2005) System Analysis and Design with UML version 2 second edition, Wiley Chapter 7 ( especially ) Further reading Bennett, S., McRobb, S. and Farmer, R. (2002) Object-Oriented Systems Analysis and Design using UML, 2nd Edition, McGraw-Hill Pages

25 Summary What CRC cards are How to use CRC cards


Download ppt "IS514 Lecture Week 9 CRC Cards."

Similar presentations


Ads by Google