chapter 9 finding objects and classes in the real world

95
1/94 Chapter 9 Chapter 9 Finding Objects and Classes Finding Objects and Classes in the Real World in the Real World

Upload: violet-ward

Post on 31-Dec-2015

28 views

Category:

Documents


1 download

DESCRIPTION

Chapter 9 Finding Objects and Classes in the Real World. Chapter 9: Finding Objects and Classes in the Real World Outline:. 9.1. The Importance of This Step 9.2. The KRB ( K apur, R avindra & B rown) Seven-Step Method 9.3. Is It A Class or Is It An Attribute? 9.4. Finding Structures - PowerPoint PPT Presentation

TRANSCRIPT

1/94

Chapter 9Chapter 9 Finding Objects and Classes Finding Objects and Classes

in the Real Worldin the Real World

2/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

Outline:Outline:9.1. The Importance of This Step

9.2. The KRB (Kapur, Ravindra & Brown) Seven-Step Method

9.3. Is It A Class or Is It An Attribute?9.4. Finding Structures9.5. Adapting the Method

Let’s check these 5 in detail. . .Let’s check these 5 in detail. . .

3/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

9.1. The Importance of This Step.9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

9.3. Is It A Class or Is It An Attribute?

9.4. Finding Structures.9.5. Adapting the Method.

4/94

9.1. The Importance of This Step. 9.1. The Importance of This Step.

The concept of classclass is one of the key things in the Object-Oriented world,

So one of the first steps is to find all the find all the classes,classes,

AllAll the classes,

That matter for this project.That matter for this project. How do we know when we have them allall

(or at least close enough)?

Read on. . . Read on. . .

5/94

9.1. The Importance of This Step. 9.1. The Importance of This Step. First we must be user-driven,user-driven, That is, we must take the attitude that

the users know users know what we need to knowwe need to know To get our job our job done properly. What follows is a reliable set of

techniques for working with the users To get from them what we need, Documented the way we need it,

To build for them the right software, the right software,

That they truly need.they truly need.

6/94

9.1. The Importance of This Step. 9.1. The Importance of This Step.

Jacobson’s Three Types Entity Objects Entity Objects - things in the users’ real world

Concrete objects - Employee, Product, Tool, etc. Conceptual objects - Corporation, strategy,

membership, approval, etc. Event and State objects - Purchase, delivery,

arrival, ownership, status, etc.

Interface ObjectsInterface Objects - To encapsulate the details of GUIs, communication protocols, and the like.

Control ObjectsControl Objects - To carry complex methods that don’t have a class they obviously belong in.

7/94

9.1. The Importance of This Step. 9.1. The Importance of This Step.

The Class Diagram is the The Class Diagram is the foundation for your entire foundation for your entire

software project!!software project!!

If this is done well,If this is done well,

You have an excellent chance You have an excellent chance of a successful project.of a successful project.

If not, you don’tIf not, you don’t

8/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

9.1. The Importance of This Step.

9.2. The KRB Seven-Step Method.9.2. The KRB Seven-Step Method.9.3. Is It A Class or Is It An

Attribute?9.4. Finding Structures.9.5. Adapting the Method.

9/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Step Define Classes

Step Establish Relationships

Step Expand Many-to-Many Relationships

Step Attributes

Step Normalization

Step Operations (i.e., Behavior)

10/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Definition:Definition:

Candidate Classes:Candidate Classes:

NounsNouns that are possible class that are possible class names, being considered for names, being considered for

inclusion in the project.inclusion in the project.

11/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Entity Classes

Things in the world of the users. These are the four most popular methods

for this step: Client Interviews Nouns from the Documentation Brainstorming

Now these four methods in detail . . .Now these four methods in detail . . .

12/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method. Step Candidate Classes

1. Client Interviews1. Client Interviews Good for busy senior executives. Adapt the group methods

(Brainstorming, etc.) to individual or small-group setting.

Possibly interview them first, then build the model away from the users.

Bring the model back to the users Bring the model back to the users regularly for feedback and input.

13/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

2. Nouns from the 2. Nouns from the DocumentationDocumentation

Use this idea by itself, or with the others.

You need nouns.nouns. Start with any or all of these documents:

Systems Request Document

Any document that describes that portion of the users’ business which you are about to model.

Change Request Document

The mandate, mission, strategic plan, etc., etc. for the users’ business.

14/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

2. Nouns from the 2. Nouns from the DocumentationDocumentation

Also go through your own documents: Your Requirements Models Project Scope Context Diagram Use Cases Interface descriptions And any other document that you think might be

a fruitful source of nounsnouns concerned in your users’ business.

15/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

3. Brainstorming 3. Brainstorming Our Class Diagram must be

based Not on the needs of the current project, But on the total data requirements of

the users’ business area.

The brainstorming method does just that . . . The brainstorming method does just that . . .

16/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

3. Brainstorming3. Brainstorming

Definition:Definition: Formal BrainstormingFormal Brainstorming takes place in two

distinct phases.

The firstfirst phase is for generatinggenerating ideas,

and the secondsecond phase is for evaluatingevaluating those ideas.

17/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

User Interfaces:User Interfaces: Your classes will be defined by your GUI tool.

Data Communications Interfaces:Data Communications Interfaces: If you buy a communications class library, your classes

are already defined for you. The published comm protocol should be filed with or

referred from your project documentation. Real-world systems to control or monitor:Real-world systems to control or monitor:

Industrial Processes, etc. Define a single-instance class to represent the external

system.

Interface ClassesInterface Classes

18/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Will mostly be discovered in the Design Phase of the OODLC.

As with anything else, if the topic arises earlier during the Analysis Phase,

Use you judgement; Either do it now, or Make serious notes to ensureensure it gets

done later. (Don’t ever miss it!)(Don’t ever miss it!)

Control ClassesControl Classes

19/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Step Define ClassesDefine Classes Step Establish Associations

Step Expand Many-to-Many Associations

Step Attributes

Step Normalization

Step Operations (i.e., Behavior)

20/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

OverviewOverview

A Real-World IdentifierIdentifier (“How do I tell one . . . from another?”)

A DefinitionDefinition (“What is a . . . ?”)

Sample AttributesAttributes and BehaviorsBehaviors

(“What might I need to know about a . . .?”

or “What can happen to a . . .?”)

Each Candidate Class must undergo three checks:

21/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Objects have Identity,Identity, So they are distinct from each other, And there is usually some way to tell them apart.tell them apart. How do we tell one StudentStudent from another?

- Different names - Different names - won’t do, not unique.

-- Also, names and such are too sensitive to errors

Punctuation and case Spelling and spacing

- Different faces - Different faces - scanning technology not yet good enough

Question 1: A Real-World IdentifierQuestion 1: A Real-World Identifier

22/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Student No. Customer No. Account No. Licence No. Serial No. Product Code Category Code Vendor ID Employee No.

Question 1: A Real-World IdentifierQuestion 1: A Real-World Identifier

Some Examples of Identifiers:Some Examples of Identifiers: Building ID Street Name City Name State/Province ID Vehicle ID No. (VIN) Inventory No. Room No. Legal Description

(Land) Policy No.

23/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

So we try to find a unique identifier for our Candidate Class.

If we can’t, then it’s definitely not a class.

If we eventually do find one, then we move on to the next test,

Question 2: The Definition . . .Question 2: The Definition . . .

Question 1: A Real-World IdentifierQuestion 1: A Real-World Identifier

24/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Question 2: The DefinitionQuestion 2: The Definition

This part has four goals:This part has four goals: DocumentDocument the users’ language and jargon

So we can learn about their business, And document it for those who may follow us.

Produce a “Dictionary” “Dictionary” to which we shall refer often in the later steps.

By having the users formally define formally define their own terms, they may resolveresolve many misunderstandings, ambiguities and unexamined assumptionsunexamined assumptions.

Finally, contribute to our decision contribute to our decision whether or not this Candidate Class is significant for our project.

25/94

God gave us two ears God gave us two ears and one mouth . . .and one mouth . . .

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Question 2: The DefinitionQuestion 2: The Definition

26/94

Your Recording Analyst Recording Analyst must have both

A DictionaryDictionary and

A ThesaurusThesaurusduring this process.

The identifier and the definition are usually enough to tell if this is a class for us,

But you may need to go to the third question,

Sample Attributes and Behaviors . . .Sample Attributes and Behaviors . . .

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Question 2: The DefinitionQuestion 2: The Definition

27/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Question 3: Sample Attributes and Question 3: Sample Attributes and BehaviorsBehaviors

Ask the users, “What might you need to know about a Student?”Student?” They’ll come up with a few things:

The name. Age Address Etc.

If these attributes exist, Then it follows that there must be a class

to attach them to!

28/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Question 3: Sample Attributes and Question 3: Sample Attributes and BehaviorsBehaviors

Similarly, you may ask the users, “What can a Student Student dodo?” Or, “What kind of things can happen tohappen to a

Student?”Student?” Again, they will come up with a few things:

He registers. She changes her address. Etc.

If these behaviors exist, then it also follows that there must be a class to attach them to!

29/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Define Classes

Question 3: Sample Attributes and Question 3: Sample Attributes and BehaviorsBehaviors

Once all of your definitions have been done, you are ready to move to Step 3: Establish Associations.Step 3: Establish Associations.

Be prepared, however, to revisit the definition step many times,

To clarify the classes you have found, And to define classes that you missed, and that

you discover in the later steps. And now,

Step 3: Establish Associations . . .Step 3: Establish Associations . . .

30/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Step Define Classes

Step Establish AssociationsEstablish Associations Step Expand Many-to-Many

Associations

Step Attributes

Step Normalization

Step Operations (i.e., Behavior)

31/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

An associationassociation is an interinteractionaction between instances of two classes,

Represented by a verb.verb. The ones we want are those that describe

things that happen in the users’ things that happen in the users’ business.business.

We need a sentence that goes

““Object Object verbverb Object” Object” And makes senseAnd makes sense in the users’ world.

32/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

There are two important parts to this sentence:

The The VerbVerb, , and

The The MultiplicityMultiplicity..

33/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

When A Customer buysbuys a Product, We hope he buys manymany of them! And when a Product is sold to is sold to a Customer,

we hope it is sold to manymany Customers. So in this particular business, The Customer-to-Product association is

Many-to-Many, Many-to-Many, or

M:MM:M

34/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

Customer

*A/c No.NameAddressPhone No.Balance

Product

*Prod No.DescriptionUnit PriceQty in Stock

buysbuys

** **

* = “many”* = “many”

35/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

“What does a Teacher DODO to a Course?” A Teacher teachesteaches a Course. How many? A Teacher teaches a lot of courses. But how many teachers teach a given But how many teachers teach a given

course?course?

Only one! Which this time gives us a

One-to-Many, One-to-Many, or

1:M1:M

36/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

Course

*Course No.*DateRoom No.Max Enrol

Teacher

*Employee No.NameAgeSexSalary

teaches

**11

* = “many”* = “many”

37/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

So this gives us the definition:

Multiplicity is the Multiplicity is the

number of instances number of instances of each class that can of each class that can

participate in the participate in the association.association.

38/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

And we must be careful not to miss any potential associations!

We must check each class each class against every every other class, other class, and each time ask:

“What does one of these DODO to one of those?”

If there is an answer, we have an association,

And we must then find the multiplicity.

39/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

If you have four classes in your model, That means you must check 8 possible

associations (there are 16 ways of combining 2 at a time out of 4

things).

If, as is more likely, you have something like 40 classes,

Then you must check 800 possibilities!

Sounds impossible?Sounds impossible?

It can be done It can be done . . .. . .

40/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

EitherEither use a grid chart with all the classes listed down the side and also listed again along the top:

Customer

Product

Vendor

Invoice

Bin

Warehouse

Cu

sto

mer

Pro

du

ct

Ven

dor

Invoic

e

Bin

Ware

hou

se

X

X

X X X X

X

XXXXX

X

X

X

XXX

41/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

OR Draw a line against the list of classes,

each time you check out a possibility. This way you check out each classeach class

against every classevery class below itbelow it in the list.

Customer

Product

Vendor

Invoice

Bin

Warehouse

42/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Establish Associations

Then, once we have the Then, once we have the associations in place, associations in place,

there is something we must do there is something we must do

to all of the M:M associations in to all of the M:M associations in the model . . .the model . . .

43/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Step Define Classes

Step Establish Associations

Step Expand Many-to-Many AssociationsExpand Many-to-Many Associations Step Attributes

Step Normalization

Step Operations (i.e., Behavior)

44/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Bo

Jo

Mo

Slo

Ko

Yo

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

Take a look at this card-and-string database:

45/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

This will allow us to do sales reports by either: Pulling a Customer card, and the strings will

bring all the relevant Product cards, Or vice-versa. But there are problems . . .

BoJo

MoSlo

Ko

Yo

Coffee

Donuts

DictionaryThesaurus

Notebook

Pencil

46/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Bo

Jo

Mo

Slo

Ko

Yo

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

Donuts

DonutsNotebook

CoffeeDonuts DictionaryThesaurus

Pencil

Bo

Slo

Jo

Jo

JoSloKo

Jo

And,And,The data is recorded in The data is recorded in twotwo places, places,

which is not good design,which is not good design,since it since it willwill get get

out of stepout of step(Murphy’s Law)(Murphy’s Law)

47/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Bo

Jo

Mo

Slo

Ko

Yo

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

Donuts

DonutsNotebook

CoffeeDonuts DictionaryThesaurus

Pencil

Bo

Slo

Jo

Jo

JoSloKo

Jo

Not only that, but where would we write the date, quantity and selling price for each sale?

On the strings, On the strings,

perhaps?perhaps?

48/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Bo

Jo

Mo

Slo

Ko

Yo

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

Bo Pencils10 Monday $.49

We replace each string with a card and two strings:We replace each string with a card and two strings:

This allows us This allows us to write the details to write the details on the card in the on the card in the

middlemiddle

49/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Bo

Jo

Mo

Slo

Ko

Yo

Bo Pencils10 Monday $.49

Ko Donuts12 Tuesday $1.49

Slo Notebook1 Friday $2.00

Slo Donuts4 Tuesday $.49

Jo Thesaurus4 Thursday $2.49

Jo Dictionary1 Wednesday $1.19

Jo Donuts3 Tuesday $.39

Jo Coffee3 Tuesday $.59

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

50/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

This card-and-string This card-and-string database can be modeled database can be modeled

with a class diagram,with a class diagram,First as a M:M. . .First as a M:M. . .

51/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Customer

*NameAddressPhone No.Balance

buysbuys

““Customer Customer buysbuys Product” Product”““Customer Customer buysbuys Product” Product”

Bo

Jo

Mo

Slo

Ko

YoBo Pencils

10 Monday $.49Ko Donuts

12 Tuesday $1.49Slo Notebook1 Friday $2.00Slo Donuts4 Tuesday $.49Jo Thesaurus

4 Thursday $2.49Jo Dictionary

1 Wednesday $1.19Jo Donuts3 Tuesday $.39

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

Jo Coffee3 Tuesday $.59

Product

*DescriptionUnit PriceQty in Stock

****

52/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Customer

*NameAddressPhone No.Balance

Product

*DescriptionUnit PriceQty in Stock

Sale

*Name*DescriptionQty SoldActual Price

Check the strings - the M:M is now 2 x 1:M !!Check the strings - the M:M is now 2 x 1:M !!Check the strings - the M:M is now 2 x 1:M !!Check the strings - the M:M is now 2 x 1:M !!

Bo

Jo

Mo

Slo

Ko

YoBo Pencils

10 Monday $.49Ko Donuts

12 Tuesday $1.49Slo Notebook1 Friday $2.00Slo Donuts4 Tuesday $.49Jo Thesaurus

4 Thursday $2.49Jo Dictionary

1 Wednesday $1.19Jo Donuts3 Tuesday $.39

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

Jo Coffee3 Tuesday $.59

isinvolved

in has

** **11 11

Which then becomes a pair of 1:MWhich then becomes a pair of 1:M

53/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

And here is the principle:A M:M relationship M:M relationship always

breaks out into a pair of 1:M,pair of 1:M,

with a new class new class in the middle,

and the “many” “many” ends

against the new class.against the new class.

54/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Variation: Collapsing Events

Customer Product

Salesperson

When you have a triangle of events like this,Very often one of them is redundant,

buys

is sold by

buys from

** ****

**

**

**

55/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Expand Many-to-Many Associations

Collapsing Events:

Customer Product

Salesperson

AndAnd often they will collapse into a singleIntersection Class like SaleSale here.

Sale

**11

11

11

****

Is involved inhas

Makes

56/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Step Define Classes

Step Establish Associations

Step Expand Many-to-Many Associations

Step Attributes Attributes Step Normalization

Step Operations (i.e., Behavior)

57/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Attributes

With the users, With the users, list all the attributes you can think of for each class on your diagram.

For a small model, list them inside the boxes on the diagram.

If there’s too many for this, list them separately as part of the textual documentation that goes with the diagram.

Then we are into the next step, Then we are into the next step,

Normalization . . .Normalization . . .

58/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Step Define Classes

Step Establish Associations

Step Expand Many-to-Many Associations

Step Attributes

Step Normalization Normalization Step Operations (i.e., Behavior)

59/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Normalization

Let’s start with an example.Say you need a sales report something like this:

Customer Catalog Unit Qty Actual ExtendedNo. Name Address No. Description Price Date Sold Price Price

131 Jo Blo 13 May St 3A21 T-Shirt 12.49 03/01/98 45 10.00 450.00179 Yo Yo 271 OK Ave 1B77 Sweats 15.00 01/03/98 12 15.00 180.00212 Mu Mu 32 Saddle Rd 4X21 Pants 23.47 12/11/98 5 21.00 105.00 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

60/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Normalization

We have:Data that describes a CustomerCustomer (Cust No./Name/Address)

Data that describes a ProductProduct (Cat No/Description/Unit Price)

And data that describes a SaleSale (Date/Quantity/Actual and Extended Prices)

Compare this situation with all the earlier models we have looked at,

You’ll see that CustomerCustomer,, ProductProduct and SaleSale should

each be a separate class . . .separate class . . .

The problem is that we have three kinds three kinds of data in this report.

61/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Normalization

Customer

*NameAddressPhone No.Balance

Product

*DescriptionUnit PriceQty in Stock

Sale

*Name*Description*DateQty SoldActual PriceExt. Price

isinvolved

in has

Bo

Jo

Mo

Slo

Ko

YoBo Pencils

10 Monday $.49Ko Donuts

12 Tuesday $1.49Slo Notebook1 Friday $2.00Slo Donuts4 Tuesday $.49Jo Thesaurus

4 Thursday $2.49Jo Dictionary

1 Wednesday $1.19Jo Donuts3 Tuesday $.39

Coffee

Donuts

Dictionary

Thesaurus

Notebook

Pencil

Jo Coffee3 Tuesday $.59

** **11 11

Like this!Like this!

62/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Normalization

So it is fair to state that

The The goalgoal of Normalization of Normalization

is to get every attributeis to get every attribute

attached to the class of attached to the class of objects objects

that it truly describes.that it truly describes.

63/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Normalization

because it is not a proper technical definition.

You’ll find a more detailed treatment of the topic in The Book at p.318.

And now the last of the KRB Seven And now the last of the KRB Seven Steps . . .Steps . . .

This is presented as the goalgoal of normalization,

64/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Candidate Classes

Step Define Classes

Step Establish Associations

Step Expand Many-to-Many Associations

Step Attributes

Step Normalization

Step Operations (i.e., Behavior) Operations (i.e., Behavior)

65/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

The final part of the analysis is to find the operations to go with the class diagram.

This is the part that is new with objects.

Chapters 10 and 11 each present a method that will help to find behaviors.

66/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

At this stage, we just need namesnames for some of the behaviors.

We just need to know what behaviors what behaviors exist.exist.

Later, in the Design phase, we’ll look at each one in detail,

And spec them out for the programmers to code.

67/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection1. By Inspection2. Basic 2. Basic CRUDCRUD3. Use Cases3. Use Cases4. Statechart Diagram4. Statechart Diagram5. CRC Cards5. CRC Cards6. 6. CRUDCRUD Revisited Revisited

Six techniques for Six techniques for Finding OperationsFinding Operations

68/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection: 1. By Inspection:

With the users, ask the question:

“What can a . . . DO?DO? For example,

What can a StudentStudent do?Create herself (i.e., her record, or instance, in the

database.Enrol himself in a class.Pay her fees.Gain a grade in a course.

69/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection: 1. By Inspection: What can a CustomerCustomer do?

Create her/himself Buy a Product Pay a bill Return a Product Change address

What can a ProductProduct do? Create Get stock in Sell some Update Unit Price Change tax status

70/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection1. By Inspection

2. Basic 2. Basic CRUDCRUD3. Use Cases3. Use Cases4. Statechart Diagram4. Statechart Diagram5. CRC Cards5. CRC Cards6. 6. CRUDCRUD Revisited Revisited

Six techniques for Six techniques for Finding OperationsFinding Operations

71/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

2. Basic CRUD: 2. Basic CRUD: Every class has to have some way for its

instances to be:

CCreatedreated

RReadead

UUpdatedpdated, and

DDeletedeleted

72/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

2. Basic CRUD: 2. Basic CRUD: Among all the behaviors, there must be

at least one behavior to look after each of these four functions.

Don’t bother writing in the four functions,but do check at the end (after the techniques from Chapters 10 and 11)

to make sure all four (C, R, U, D) (C, R, U, D) have been looked after,

For each classFor each class..

73/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection1. By Inspection2. Basic 2. Basic CRUDCRUD

3. Use Cases3. Use Cases4. Statechart Diagram4. Statechart Diagram5. CRC Cards5. CRC Cards6. 6. CRUDCRUD Revisited Revisited

Six techniques for Six techniques for Finding OperationsFinding Operations

74/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

3. Use Cases: 3. Use Cases:

Scan your Use Cases,and at each step,

Consider what behaviors the objects would need to performto output or input the data you need for the Use Case.

75/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection1. By Inspection2. Basic 2. Basic CRUDCRUD3. Use Cases3. Use Cases

4. Statechart Diagram4. Statechart Diagram5. CRC Cards5. CRC Cards6. 6. CRUDCRUD Revisited Revisited

Six techniques for Six techniques for Finding OperationsFinding Operations

76/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

4. Statechart Diagram: 4. Statechart Diagram:

The Statechart DiagramStatechart Diagram can be a fruitful source of behaviors.

It is favored by several of the Gurus,

Among them Shlaer and Mellor, And James Rumbaugh et al. We will study the Statechart Statechart

DiagramDiagram in detail in Chapter 10.

77/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection1. By Inspection2. Basic 2. Basic CRUDCRUD3. Use Cases3. Use Cases4. Statechart Diagram4. Statechart Diagram

5. CRC Cards5. CRC Cards6. 6. CRUDCRUD Revisited Revisited

Six techniques for Six techniques for Finding OperationsFinding Operations

78/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

5. CRC Cards: 5. CRC Cards:

Rebecca Wirfs-Brock et al introduced the Class-Responsibility-Collaboration Cards

(CRC Cards) They work well to trace the interactions

among the various classes, As they “collaborate” to get a task done. We will use CRC cards extensively in

Chapter 10, and also in Chapter 13.

79/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

1. By Inspection1. By Inspection2. Basic 2. Basic CRUDCRUD3. Use Cases3. Use Cases4. Statechart Diagram4. Statechart Diagram5. CRC Cards5. CRC Cards

6. 6. CRUDCRUD Revisited Revisited

Six techniques for Six techniques for Finding OperationsFinding Operations

80/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

6. CRUD Revisited: 6. CRUD Revisited:

When you think you have exhausted all the possibilities for finding behaviors,

Then for each class you need to do a

CRUD Matrix. . .CRUD Matrix. . .

81/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

6. CRUD Revisited: 6. CRUD Revisited:

List business functionsbusiness functions across the top Or if you need to, across the top you can

list any of these: Organization units Positions (i.e., jobs) People Use Cases

Then you mark in each column what these people can do to this class . . .

List your classesclasses down the left.

82/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

6. CRUD Revisited: 6. CRUD Revisited:

Only Only Management Management can can DeleteDelete Customers.Customers.

CustomerCustomer

ProductProduct

..

..

..

..

SaleSale

D

Mar

ketin

g

Mar

ketin

gBuye

rs

Buyers

Sales

Sales

Man

agem

ent

Man

agem

ent

CRU

........

Inve

ntory

Inve

ntory

83/94

9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.

Step Operations (i.e., Behavior)

6. CRUD Revisited: 6. CRUD Revisited:

CustomerCustomer

ProductProduct

..

..

..

..

SaleSale

Mar

ketin

g

Mar

ketin

gBuye

rs

Buyers

Sales

Sales

Man

agem

ent

Man

agem

ent

CRU D

Then the rest Then the rest of the matrixof the matrixmight go like thismight go like this

RU

RU CRU RU CRUD

R R CRU RD

Inve

ntory

Inve

ntory

........

84/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

9.1. The Importance of This Step.9.2. The KRB Seven-Step Method.

9.3. Is It A Class or Is It An Attribute?9.3. Is It A Class or Is It An Attribute?9.4. Finding Structures.9.5. Adapting the Method.

85/94

When you apply the first two questions to a Candidate Class: What is a . . . ? (Definition) How do I tell one . . . from another?

(Identifier)

Often these are still not enough to tell if this is a classclass,

or just an attributeattribute of some class.

9.3. Is It A Class or Is It An Attribute? 9.3. Is It A Class or Is It An Attribute?

This is a frequent problem during Analysis.

86/94

is the third question:third question:

Sample Attributes or Behaviors.Sample Attributes or Behaviors.

If there are attributesattributes to describe it, And/or behaviorsbehaviors it can do

(or have done to it)

Then there must be a class Then there must be a class to attach them to!to attach them to!

9.3. Is It A Class or Is It An Attribute? 9.3. Is It A Class or Is It An Attribute?

The key to deciding

87/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

9.1. The Importance of This Step.9.2. The KRB Seven-Step Method.9.3. Is It A Class or Is It An Attribute?

9.4. Finding Structures.9.4. Finding Structures.9.5. Adapting the Method.

88/94

9.4. Finding Structures.9.4. Finding Structures.

Subclass HierarchiesSpecializationGeneralization

AggregationsComponents and WholesContainer-ContentsCollection-Member

89/94

9.4. Finding Structures.9.4. Finding Structures.

Subclass Hierarchies

Look for kindsakindsa in all your classes Are there attributes or operations that

are only needed by certain instances certain instances and not by the entire class?

Do some relationships affect only a

subsetsubset within the class? Could this class this class be viewed as a

subclass of subclass of something in your class libraries?

Specializations:

90/94

9.4. Finding Structures.9.4. Finding Structures.

Does there seem to be a cluster of.

• Attributes,Attributes,

• Operations orOperations or

• AssociationsAssociations

that appear in several classes?

Consider semantics - (remember the cow and the barn, p126)

Generalizations:

91/94

9.4. Finding Structures.9.4. Finding Structures.

Are there any attributes on this class that don’t really describe “one of these” “one of these” but rather

some object that is in some way ““withinwithin” ” it? Any operations that are performed by a “piece” “piece”

of the object, not the object itself? Associations that involve only a “piece”“piece” or “part”“part”

of the object? Check other models in the same business area,

possibly from other companies.

AggregationsComponents and WholesContainer-ContentsCollection-Member

92/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

9.1. The Importance of This Step.9.2. The KRB Seven-Step Method.9.3. Is It A Class or Is It An Attribute?9.4. Finding Structures.

9.5. Adapting the Method.9.5. Adapting the Method.

93/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

It can be easily adapted to other It can be easily adapted to other situations:situations:

One-on-one client interviewsOne-on-one client interviews

Delphi MethodDelphi Method Meet, combine, circulate Meet, combine, circulate

The KRB Method works well in JAD sessionsThe KRB Method works well in JAD sessions

The most critical factor isThe most critical factor is

User InvolvementUser Involvement

94/94

Chapter 9: Finding Objects and Chapter 9: Finding Objects and Classes in the Real WorldClasses in the Real World

Make an adequate commitment of timeMake an adequate commitment of time Have good warning of the time Have good warning of the time

commitment that will be required of commitment that will be required of themthem

Be high-caliber workers who know Be high-caliber workers who know their field or profession thoroughlytheir field or profession thoroughly

Be chosen from a variety of levelsBe chosen from a variety of levels

The users must:The users must:

95/94

End of Chapter 9