Docsity

Finding Class Attributes and Behaviors: Association Class and CRC Cards, Slides of Object Oriented Programming

Toggle sidebar
bg1
1
Classes and Class Diagrams
for
Requirements Analysis
(continued…)
Lecture 21
Finding Attributes
Associations:
Implementation point of view
nTwo classes A and B are associated, if:
1. An instance of class A sends a message to
an instance of class B
2. An instance of class A creates an instance
of class B
3. An instance of class A has one or more
attributes whose values are instances of
class B
4. An instance of class A receives a message
with an instance of class B as an
argument
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Finding Class Attributes and Behaviors: Association Class and CRC Cards and more Slides Object Oriented Programming in PDF only on Docsity!

Classes and Class Diagrams

for

Requirements Analysis

(continued…)

Lecture 21

Finding Attributes

Associations:

Implementation point of view

n Two classes A and B are associated, if:

1. An instance of class A sends a message to

an instance of class B

2. An instance of class A creates an instance

of class B

3. An instance of class A has one or more

attributes whose values are instances of

class B

4. An instance of class A receives a message

with an instance of class B as an

argument

docsity.com

Implementation of Point 3

n An instance of class A has one or more

attributes whose values are instances

of class B

class A {

B b; // declare ‘b’

void somethingACanDo() {

b = anotherInstanceOfClassB;

UML Representation of Point 3

A

  • b1 : B
  • b2 : B

A B

  • c : int
  • d : String

A B

  • c : int
  • d : String

more precisely

Conversely…

A

  • b : B

A B

  • c : int
  • d : String

B

  • a : A

A

  • aMethod(b : B)

B

  • aMethod(a : A)

docsity.com

Example

RetailShop Item

sells

What if information about a particular sales has to be

preserved? For example:

- Shop Number

- Item Number

- Date of Sale

- Sale Value

- Warranty Type

- Warranty Expiry Date

The Association Class

RetailShop Item

sells

Sale

Also known as LINK ELEMENT in Rational Rose

Another example

Student Course

takes

Grade

  • mark : int

docsity.com

Implementation of Student

#include "Grade.h"

class Student

public:

Grade* get_Grade();

void set_Grade(Grade* ptr);

private:

Grade* grade;

Grade* Student::get_Grade()

return grade;

void Student::set_Grade (Grade*

ptr)

grade = ptr;

Additional Comments

The problem in the Student class is that a particular

Student has several links (and an equal no. of

Grade instances) with Course objects. The

get_Grade and set_Grade methods however do not

specify which Grade instance to get or set.

After you understand the problem, here are few tips to

solve the problem:

1. #include “Course.h”

2. Grade* Student::getGrade(Course* c);

3. Grade* Student::setGrade(Grade* ptr, Course* c);

Implementation of Course

#include "Grade.h"

class Course

public:

Grade* get_Grade();

void set_Grade(Grade* ptr);

private:

Grade* grade;

Grade* Course::get_Grade()

return grade;

void Course::set_Grade (Grade*

ptr)

grade = ptr;

docsity.com

Format of a CRC Card

Responsibilites of a class are listed in this section

Collaborations with other classes are listed here, together with a brief description of the purpose of the collaboration

Responsibilities Collaborations

Class Name

15 cm

8 cm

Process of using CRC Cards

n Identify classes/ objects

n Allocate each object to a team member who will role

play the object

n Role play a scenario of the use case exploring and

recording responsibilities and collaborations

n Identify and record any missing or redundant objects

Library Member borrows a

Copy of a Book

Maintain data about one book

Maintain a count of borrowable copies

Responsibilities Collaborations

Book

Maintain data about the number of books borrowed

Make request to borrow copy

Make request to return copy

Copy

Copy

Responsibilities Collaborations

LibraryMember

Maintain data about a particular copy of a book Inform corresponding Book when borrowed

Inform corresponding Book when returned

Book

Book

Responsibilities Collaborations

Copy

docsity.com

Summary

n Review of Finding class attributes and

behaviors

n Association Class (Link Element)

n CRC Cards

docsity.com