Unit 2: Use Case Analysis: Module 3: Class Responsibility Collaboration Cards

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Unit 2: Use Case Analysis

Module 3: Class Responsibility


Collaboration Cards
Objectives
 Understand the different approaches to confirming
candidate entity classes
 Able to identify responsibilities and collaborations for a
class
 To create Class Responsibility Collaboration Cards
 To update the Noun Extraction Table
Confirming Candidate Classes
 Before we do anything else, we need to add content to
the extracted classes to confirm that they are classes.

 There are three basic approaches for "fleshing out" our


analysis classes:
◦ A data-driven approach
◦ A behaviour-driven approach, or
◦ A responsibility-driven approach.
…Confirming Candidate Classes
 Data-driven approach:
◦ Popular with people coming from a database, or procedural,
background.
◦ They see the world in terms of data, relationships, and tend to
populate their classes first with data -- usually with no strategy on
how to assign operations (i.e., functions) to the class.

 Behavior-driven approach:
◦ Populates a class first with the operations that the class will
perform, and determines from those operations the data that
should be owned by the class.
◦ How do you know that the operation belongs with the correct
class? There is no clear way of knowing.
…Confirming Candidate Classes
 Responsibility-driven approach:
◦ Starts with a large-grained view of the class and first
assigns responsibilities to that class.
◦ This approach describes first the "mission" statement of
a class in the context of the problem domain in which we
are working.
 This mission statement is a declaration of the services the
class will provide to requestors of those services.
◦ In military terms, the responsibilities are strategic; the
operations and data are tactical (subservient to, and a
means of achieving, the strategy).
 The operations and attributes provide a means to
achieving the requested responsibilities.
What is a Responsibility?
 Responsibility: is a contract or
obligation of the class and later
translates into operations and
attributes as models are refined.
…What is a Responsibility?
 When you create a class, you are
making a statement that all objects
of that class should have the same
responsibilities that is realized
through operations and attributes.
 This means the responsibilities of a

class are carried out by its


operations and attributes.
Why Responsibilities?
 James Rumbaugh et al. defines an object or class as “a
concept, abstraction, or thing with crisp boundaries and
meaning for the problem at hand”.
 Through responsibilities you can give a class crisp
boundaries, a clear definition of what the class does,
and does not do.

Class Name Student


First Name
Attributes Student#: UniqueId

create()
save()
Operations
delete()
change()
Describing Class Responsibilities
 Each analysis class may have several
responsibilities
◦ A class with only one responsibility is probably too simple.
◦ A class with a dozen or more is pushing the limit of
reasonability and should potentially be split into several
classes.
◦ Responsibilities can evolve into one (but usually more)
operations on classes in design.

 The responsibilities of a class should not describe


how it is performed.
Finding Responsibilities
 A responsibility is anything that a class knows or does.
◦ For example, students have names, addresses, and phone
numbers. These are the things a student class knows about a
student.
◦ For example, the student class allows the system to add a
student. The course class allows a student to enroll in courses, to
drop a course. These are the things a student and course class
does respectively.

 Important: A class is able to change the values of the


things it knows, but it is unable to change the values of
what other classes know.

Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
…Finding Responsibilities
 To find responsibilities:
◦ Ask yourself what the class does, and
◦ What information do you wish to maintain about the class.
 Note: You will often identify a responsibility for a class to
fulfill a collaboration with another class.

Class Name Student


First Name
Attributes Student#: UniqueId Knows

create()
Operations save() Does
delete()
change()

Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
Collaborations
 Sometimes a class has a responsibility to
fulfill, but not enough information to do so.
◦ For example, a student enroll in a course. To do this, a
student needs to know if a spot is available in the
course and, if so, he then needs to be added to the
course.
◦ However, the student class only have information
about themselves (their names and so forth), and not
about a course.
◦ What the student class needs to do is
collaborate/interact with the Course class to sign up for
a course.

Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
…Collaborations
 Collaboration takes one of two forms:
◦ A request for information
 For example, the Student requests an indication from the
Course class whether a space is available.
◦ A request to do something.
 The Student then requests to be added to the Course class, a
request to do something.

◦ Another way to perform this logic would have been


 The Student request the Course class to enroll himself into the
Course.
 The Course class is then responsible to determining if a seat is
available and, if so, then enrolling the Student and, if not, then
informing the Student that he was not enrolled.
Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
Finding Collaborations
 A class often does not have sufficient information
(data) to fulfill its responsibilities.
◦ Therefore, it must collaborate (work) with other classes to
complete the required responsibility.

 To identify the collaborators of a class for each


responsibility ask yourself “does the class have the
ability to fulfill this responsibility on its own? ”
◦ If not, look for a class that has the ability to fulfill the
missing responsibilities or a class which should fulfill it.
◦ In doing so you'll often discover the need for new
responsibilities in other classes and maybe even the need
for a new class or two.
Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
Guidelines: CRC card
Class Responsibility Collaboration Card
Class Name
RESPONSIBILITY COLLABORATION

 Enter the name of the class in the CRC Card


 Under the responsibility list the responsibilities that the
class may be responsible for.
 Under the collaboration list the other classes that may be
invoked in order to achieve the responsibilities through
collaboration with other classes.

Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
Class Responsibilities
 Recap:
◦ A responsibility is anything that a class Knows, or
 For example, students have a student number, first name,
surname. These are the things a student class knows about a
student.
◦ A responsibility is anything that a class Does.
 For example, the student class allows the system to create new
student. These are the things a student class does respectively.
Class Responsibility Collaboration Card
Student Class
RESPONSIBILITY COLLABORATION
Knows Student No
Knows First Name
Knows Surname
Add a Student

Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
Class Collaborations
 Collaboration takes one of two forms:
◦ A request for information, or
 For example, a Student may request information from the Course class
◦ A request to do something.
 For example, a student enroll into a course. To do this, a student needs
to know if a spot is available in the course and, if so, he then needs to
be added to the course.
 What the student needs to do is collaborate/interact with the Course
class to sign up for a course.
 Therefore, Course is included in the list of collaborators of the Student
class.
Class Responsibility Collaboration Card
Student Class
RESPONSIBILITY COLLABORATION
Knows Student No
Create a Student
Enrols into a Course Course

Ambler, S. W. (n.d.). Class Responsibility Collaborator (CRC) Models. Retrieved September 19, 2011, from Agile
Modeling: http://www.agilemodeling.com/artifacts/crcModel.htm
Review
 What is the difference between the three approaches to
confirming classes?
 What is a Responsibility?
 What should you look for when finding responsibilities?
 What is a Collaboration?
 What forms can a Collaboration take on?
 How do you know that a responsibility should have a
collaboration with another class?

You might also like