Upload
dominic-reed
View
224
Download
1
Tags:
Embed Size (px)
Citation preview
How to find objectsHow to find objects
9.1. The Importance of This Step. 9.1. The Importance of This Step.
Jacobson’s Three TypesJacobson’s Three Types Entity Objects Entity Objects - things in the users’ real world- things in the users’ real world
ConcreteConcrete objects - Employee, Product, Tool, etc.objects - Employee, Product, Tool, etc.
ConceptualConceptual objects - Corporation, strategy, objects - Corporation, strategy, membership, approval, etc. membership, approval, etc.
Event and State Event and State objects - Purchase, delivery, objects - Purchase, delivery, arrival, ownership, status, etc. arrival, ownership, status, etc.
Interface ObjectsInterface Objects - - To encapsulate the details of To encapsulate the details of GUIs, GUIs, communication protocols, and the like.communication protocols, and the like.
Control ObjectsControl Objects - - To carry complex methods that don’t have a class they To carry complex methods that don’t have a class they obviously belong in.obviously belong in.
The KRB Seven-Step Method The KRB Seven-Step Method
Step Step Candidate ClassesCandidate Classes Several ways to find Several ways to find nounsnouns that might turn out to be names of that might turn out to be names of
classes that matter to your project.classes that matter to your project.
Step Step Define Classes Define Classes Here we check for the meaning the Here we check for the meaning the usersusers attach to each noun, and attach to each noun, and
decide whether it is important decide whether it is important for this project.for this project.
Step Step Establish Associations Establish Associations Checking how these things interact gives us a picture of the Checking how these things interact gives us a picture of the
pathways that exist throughout the datapathways that exist throughout the data
Step Step Expand Many-to-Many Associations Expand Many-to-Many Associations An essential step that generates much discussion and An essential step that generates much discussion and
more classes.more classes.
9.2. The KRB Seven-Step Method 9.2. The KRB Seven-Step Method OverviewOverviewStep Step Attributes Attributes
We list out all the data fields the users need to keep We list out all the data fields the users need to keep aboutabout each each thingthing (i.e., (i.e., aboutabout each type of entity).each type of entity).
Step Step NormalizationNormalization A technical consideration, with a different relevance in the A technical consideration, with a different relevance in the
object paradigm. This step is done behind closed doors object paradigm. This step is done behind closed doors without the users.without the users.
Step Step Operations (i.e., Behavior)Operations (i.e., Behavior) This is the additional step that distinguishes objects from This is the additional step that distinguishes objects from
entities and earlier models. This part is the subject of entities and earlier models. This part is the subject of Chapters 10 and 11.Chapters 10 and 11.
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Candidate ClassesCandidate Classes
Definition:Definition:
Candidate Classes:Candidate Classes:
NounsNouns that are possible class names, that are possible class names, being considered for inclusion in the being considered for inclusion in the
project.project.
Just find all the names!Just find all the names!
The sources of entity objectsThe sources of entity objects
1. Client Interviews1. Client Interviews2. Nouns from the Documentation2. Nouns from the Documentation3. Brainstorming3. Brainstorming
The sources of interface objectsThe sources of interface objects
User Interfaces:User Interfaces: Your classes will be defined by your GUI tool.Your classes will be defined by your GUI tool.
Data Communications Interfaces:Data Communications Interfaces: If you buy a communications class library, your classeIf you buy a communications class library, your classe
s are already defined for you.s are already defined for you. The published comm protocol should be filed with or rThe published comm protocol should be filed with or r
eferred from your project documentation.eferred from your project documentation. Real-world systems to control or monitor:Real-world systems to control or monitor:
Industrial Processes, etc.Industrial Processes, etc. Define a single-instance class to represent the externDefine a single-instance class to represent the extern
al system.al system.
Will mostly be discovered in the Design Phase of the Will mostly be discovered in the Design Phase of the OODLC.OODLC.
As with anything else, if the topic arises earlier during the As with anything else, if the topic arises earlier during the Analysis Phase,Analysis Phase,
Use you judgement;Use you judgement; Either do it now, orEither do it now, or Make serious notes to Make serious notes to ensureensure it gets done later. it gets done later. (Don’t (Don’t
ever miss it!)ever miss it!)
Control classesControl classes
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Define ClassesDefine Classes
A Real-World A Real-World IdentifierIdentifier
(“How do I tell one . . . from another?”)(“How do I tell one . . . from another?”)
A A DefinitionDefinition (“What is a . . . ?”) (“What is a . . . ?”)
Sample Sample AttributesAttributes and and BehaviorsBehaviors
(“What might I need to know (“What might I need to know aboutabout a . . .?” a . . .?”
or “What can happen to a . . .?”)or “What can happen to a . . .?”)
Each Candidate Class must undergo three checks:
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Define ClassesDefine Classes
Objects have Objects have Identity,Identity, So they are distinct from each other,So they are distinct from each other, And there is usually some way to And there is usually some way to tell them apart.tell them apart. How do we tell one How do we tell one StudentStudent from another? from another?
- Different names - Different names - won’t do, not unique.- won’t do, not unique.
-- Also, names and such are too sensitive to errors Also, names and such are too sensitive to errors Punctuation and casePunctuation and case Spelling and spacing Spelling and spacing
- Different faces - Different faces - scanning technology not yet - scanning technology not yet good enoughgood enough
Question 1: A Real-World IdentifierQuestion 1: A Real-World Identifier
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Define ClassesDefine Classes
Student No.Student No. Customer No.Customer No. Account No.Account No. Licence No.Licence No. Serial No.Serial No. Product CodeProduct Code Category CodeCategory Code Vendor IDVendor ID Employee No.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.
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Define ClassesDefine Classes
So we try to find a unique identifier for our So we try to find a unique identifier for our Candidate Class.Candidate Class.
If we can’t, then it’s definitely not a class.If we can’t, then it’s definitely not a class. If we eventually do find one, then we move on If we eventually do find one, then we move on
to the next test,to the next test,
Question 2: The Definition . . .Question 2: The Definition . . .
Question 1: A Real-World IdentifierQuestion 1: A Real-World Identifier
Employee: A person who works at XYZ Widgets.Employee: A person who works at XYZ Widgets. Sounds reasonable, but do we simply delete the records when (s)he Sounds reasonable, but do we simply delete the records when (s)he
quits? Try this:quits? Try this: Employee: A person who works, or has worked, at XYZ Widgets.Employee: A person who works, or has worked, at XYZ Widgets. Better, and this will work for most businesses.Better, and this will work for most businesses. But you may find a company that wants But you may find a company that wants prospectiveprospective employees to be kept employees to be kept
in the database! Try this:in the database! Try this:
Employee: A person who works, has worked, or may in the Employee: A person who works, has worked, or may in the future work at XYZ Widgets.future work at XYZ Widgets.
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Define ClassesDefine Classes
Question 2: The DefinitionQuestion 2: The Definition
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Establish AssociationsEstablish Associations
Here we ask the questions:Here we ask the questions: ““What does a Student What does a Student DODO to a Course?” to a Course?” Enrols in Enrols in it, of course.it, of course. ““What does a Customer What does a Customer DODO to a Product?”to a Product?” A Customer A Customer buysbuys a Product.a Product.
““What does a Teacher What does a Teacher DODO to a Course?”to a Course?” A Teacher A Teacher teachesteaches a Course.a Course.
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Establish AssociationsEstablish Associations
Here we ask the questions:Here we ask the questions: ““What does a Student What does a Student DODO to a Course?” to a Course?” Enrols in Enrols in it, of course.it, of course.
““What does a Customer What does a Customer DODO to a Product?”to a Product?” A Customer A Customer buysbuys a Product.a Product.
““What does a Teacher What does a Teacher DODO to a Course?”to a Course?” A Teacher A Teacher teachesteaches a Course.a Course.
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Establish AssociationsEstablish Associations
An An associationassociation is an is an interinteractionaction between instances of two between instances of two
classes,classes,
Represented by a Represented by a verb.verb. The ones we want are those that describe The ones we want are those that describe
things that happen in the users’ business.things that happen in the users’ business. We need a sentence that goes We need a sentence that goes
““Object Object verbverb Object” Object” And makes senseAnd makes sense in the users’ world. in the users’ world.
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Establish AssociationsEstablish Associations
There are two important parts to this There are two important parts to this sentence:sentence:
The The VerbVerb, , and and
The The MultiplicityMultiplicity..
The KRB Seven-Step Method. The KRB Seven-Step Method.
Step Step Establish AssociationsEstablish Associations
Draw a line against the list of classes,Draw a line against the list of classes,
each time you check out a possibility.each time you check out a possibility.
This way you check out This way you check out each classeach class
against against every classevery class below itbelow it in the list. in the list.
Customer
Product
Vendor
Invoice
Bin
Warehouse
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
Bo
Jo
Mo
Slo
Ko
Yo
Coffee
Donuts
Dictionary
Thesaurus
Notebook
Pencil
Take a look at this card-and-string database:
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
This will allow us to do sales reports by either:This will allow us to do sales reports by either: Pulling a Customer card, and the strings will Pulling a Customer card, and the strings will
bring all the relevant Product cards,bring all the relevant Product cards, Or vice-versa.Or vice-versa. But there are problems . . .But there are problems . . .
BoJo
MoSlo
Ko
Yo
Coffee
Donuts
DictionaryThesaurus
Notebook
Pencil
More realistically, we could perhaps write on the cards More realistically, we could perhaps write on the cards instead of using strings:instead of using strings:
As you can easily see As you can easily see on Jo’s card, we are on Jo’s card, we are
likely to run out of likely to run out of
room!room!
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
Bo
Jo
Mo
Slo
Ko
Yo
Coffee
Donuts
Dictionary
Thesaurus
Notebook
Pencil
Donuts
DonutsNotebook
CoffeeDonuts DictionaryThesaurus
Pencil
Bo
Slo
Jo
Jo
JoSloKo
Jo
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
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 getout of stepout of step
(Murphy’s Law)(Murphy’s Law)
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
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, Not only that, but where would we write the date, but where would we write the date, quantity and selling price for each sale?quantity and selling price for each sale?
On the strings, On the strings,
perhaps?perhaps?
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
Bo
Jo
Mo
Slo
Ko
Yo
Coffee
Donuts
Dictionary
Thesaurus
Notebook
Pencil
Bo Pencils
We replace each string with a card and two strings:We replace each string with a card and two strings:
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
Bo
Jo
Mo
Slo
Ko
Yo
Coffee
Donuts
Dictionary
Thesaurus
Notebook
Pencil
Bo Pencils
We replace each string with a card and two strings:We replace each string with a card and two strings:
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
Bo
Jo
Mo
Slo
Ko
Yo
This allows us This allows us to write the details to write the details on the card in the on the card in the
middlemiddleCoffee
Donuts
Dictionary
Thesaurus
Notebook
Pencil
Bo Pencils
We replace each string with a card and two strings:We replace each string with a card and two strings:
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
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
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
Now let’s do Now let’s do
the rest:the rest:
Now let’s do Now let’s do
the rest:the rest:
Bo
Jo
Mo
Slo
Ko
Yo
Coffee
Donuts
Dictionary
Thesaurus
Notebook
Pencil
Bo Pencils10 Monday $.49
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
Bo
Jo
Mo
Slo
Ko
Yo
Coffee
Donuts
Dictionary
Thesaurus
Notebook
Pencil
Bo Pencils10 Monday $.49
Ko Donuts12 Tuesday $1.49
Slo Notebook1 Friday $2.00
Slo Donuts4 Tuesday $.49
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
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
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Expand Many-to-Many Expand Many-to-Many AssociationsAssociations
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
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step
AttributesAttributes
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step
NormalizationNormalization
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Normalization Normalization
Let’s start with an example.Let’s start with an example.
Say you need a sales report something like this: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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Normalization Normalization
is to build a is to build a relational table relational table
that that mimics this report.mimics this report. That is, it has the That is, it has the same columns same columns as this report.as this report. In the object paradigm, the In the object paradigm, the equivalent error equivalent error
would be to create a class with would be to create a class with attributesattributes
that that match the columns match the columns on the report.on the report. But what would we call this class?But what would we call this class? The best name would probably be something like The best name would probably be something like “Sales” “Sales” or or “Sales “Sales
Analysis.”Analysis.”
But . . .But . . .
What the uninitiateduninitiated (read “amateuramateur”) database designer tends to do
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Normalization Normalization
We have:We have:
Data that describes a Data that describes a CustomerCustomer (Cust No./Name/Address)(Cust No./Name/Address)
Data that describes a Data that describes a ProductProduct (Cat No/Description/Unit Price)(Cat No/Description/Unit Price)
And data that describes a And data that describes a SaleSale (Date/Quantity/Actual (Date/Quantity/Actual and Extended Prices)and Extended Prices)
Compare this situation with all the earlier models we have looked at,Compare this situation with all the earlier models we have looked at,
You’ll see that You’ll see that CustomerCustomer, , ProductProduct and and SaleSale should each be a should each be a sseparate class . . .eparate class . . .
The problem is that we have three kinds three kinds of data in this report.
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Normalization 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!
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step
Operations Operations (i.e., Behavior) (i.e., Behavior)
9.2. The KRB Seven-Step Method. 9.2. The KRB Seven-Step Method.
Step Step Operations (i.e., Behavior) 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