l10-s1object identification- 2 2003 sjsu -- cmpe advanced object-oriented analysis & design dr....

37
2003 SJSU -- CmpE L10-S1 Object Identification- 2 Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State University One Washington Square San José, CA 95192-0180 http://www.engr.sjsu.edu/~fayad

Post on 20-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU -- CmpE L10-S1 Object Identification- 2

Advanced Object-Oriented Analysis & Design

Dr. M.E. Fayad, Professor

Computer Engineering Department, Room #283I

College of Engineering

San José State University

One Washington Square

San José, CA 95192-0180

http://www.engr.sjsu.edu/~fayad

Page 2: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S2 Object Identification- 2

2

Lesson 10:Object Identification - 2

Page 3: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S3 Object Identification- 2

Lesson Objectives

Objectives

3

+ Learn how to identify:

Associations and aggregations

Attributes

Behaviors

Inheritance

+ Understand how to use the following approaches:

Use Case

CRC

Questioning Techniques

+ Understand how to refine objects and associations

+ Learn how to define responsibility & collaborations

+ Learn how to eliminate unnecessary classes, associations, and attributes

Page 4: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S4 Object Identification- 2

4

Automated Teller Machine (ATM)

Stop bothering me!I told you I don’t have

any money!

Page 5: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S5 Object Identification- 2

5

Actors

Customer

Bank System

Automated Teller

Machine

ATM Operator

In Use Cases, Everything that interacts with the system will be modeled as an actor, such as persons as well as machines.

Page 6: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S6 Object Identification- 2

6

Use Cases in ATM

Customer

Bank System

Cash Withdrawal

Transfer Funds

Deposit Funds

Automated Teller Machine

Balance Inquiry

System Start

ATM Operator

Page 7: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S7 Object Identification- 2

Use Case: Cash Withdrawal When a customer inserts a card in the ATM, the machine

reads the code from the card and checks if it is a valid card. If the card is valid then the machine queries the customer for a PIN number, else the card is ejected.

When the machine matches customer coded in the PIN number, the machine checks the validity of the PIN number. If the PIN number is correct and matches the card number then the machine asks for the desired transaction the customer wishes to perform.

When the customer selects cash withdrawal the machine asks for the desired amount with a warning indicating only multiple of $10 is allowed.

When .... 7

A Use Case Description: Cash Withdrawal

Page 8: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S8 Object Identification- 2

8

Candidate Objects

Account ATM Balance Inquiry Bank Card Reader Cancel Key Cash Dispenser Deposit Slot Deposit Funds Display Screen (Bank System

Interface) Menu (Graphical User Interface)

• User Message

• Numeric Keypad

• Numeric Input Key

• PIN

• Cash

• Receipt Printer

• Special Input Key

• Transfer Funds

• Cash Withdrawal

Page 9: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S9 Object Identification- 2

Define Responsibilities

– What are the goals of the system

– What must objects know to meet goals

– What steps must each object accomplish

Determine Collaborations

– Decompose responsibilities into interactions among objects

– Define clients and servers

– Where should knowledge be held 9

System Responsibilities & Collaborations

Page 10: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S10 Object Identification- 2

10

CRC Cards General

– Each class is described on a separate 3X5 or 4X6 card The cards are known as CRC card. They have 3 sections:

– Class

– Responsibilities

– Collaborations

ATM (role)

Responsibility Collaboration

Clients Server

Access & modify account balance Account Balance Inquiry Deposit Transaction Funds Transfer Withdrawal Transaction

Page 11: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S11 Object Identification- 2

Generalize and Specialize objects

Associate Objects

Recognize Accidental Objects

Challenging and Testing Objects

Ask Questions 11

Other Techniques Help Refine Objects

Page 12: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S12 Object Identification- 2

Generalization exposes commonalities

Exercise helps to identify new classes

Considerations for generalizations and specializations

– Is it in the problem domain?

– Is it within the system’s responsibilities?

– Will there be inheritance? 12

Explore Generalizations and Specializations

Page 13: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S13 Object Identification- 2

Essential objects represent genuine high-level abstractions

Accidental objects represent qualitative judgments

13

Avoid Accidental Objects

Page 14: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S14 Object Identification- 2

Needed Remembrance -- attributes

Needed Behavior -- methods

Usually Multiple Services per Object

Usually More than One Object per Class

14

Challenge Objects

Page 15: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S15 Object Identification- 2

Uniformity Test– Each instance must have the same set of characteristics

and be subject to the same rules - Car license More than a Name Test

– Every object has attributes, if not it is probably an attribute of another object -- home address

Or Test– If inclusion criteria should not use “OR” in any

significant way -- driver’s license number or learner’s permit number

More Than a List Test– If inclusion criteria is only a list of instances -- decadent

foods includes croissant , cappuccino, chocolate pie, ice cream.

15

Other Object Tests

Page 16: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S16 Object Identification- 2

Something universal and real for reuse

Should encapsulate some reasonably complex behavior to justify existence

Methods that don’t make use of its current class’s own attributes is probably encapsulated in the wrong object.

Small and simple stable interfaces

Self sufficient and complete 16

Final Object Checklist

Page 17: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S17 Object Identification- 2

Play Twenty Questions– Is it animal, vegetable, or mineral?– Does it have fur or feathers?– Can it fly?

Define Boundaries– What else?– What about..?

Quantify Qualities as Attributes – How fast?– How hot? 17

Questioning Techniques Help Elicit Domain Knowledge

Page 18: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S18 Object Identification- 2

Irrelevant Associations– outside problem domain

Implementation Associations– Examples: concurrent process,

contains a list

Associations Between Eliminated Classes

18

Eliminating Unnecessary Associations

Page 19: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S19 Object Identification- 2

Actions or Transient Events– Examples: “Interacts with the Robot”, “ATM

accepts cash card.”

Ternary Associations– Decompose as binary associations or rephrase

to one binary association.

Derived Associations– These are redundant

– Examples: “Younger than ..” derived from age 19

Eliminating Unnecessary Associations (cont’d)

Page 20: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S20 Object Identification- 2

Choose meaningful association names Add role names where appropriate Add attributes or associations which qualify existing

associations– Example: “Standard Oil of Ohio” uses state attribute to

qualify company name. Specify one-to-many and many-to-many associations

in the class diagram Add missing associations

– Not in problem statement– from knowledge of application domain

20

Refine Association List

Page 21: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S21 Object Identification- 2

Attributes can be thought as a simple association with a value which is not an object

– Examples: name, age, weight

Usually corresponding to nouns followed by possessive phrases

– Examples: “color of the car”, “age of the donor”

Less likely to be fully described in the problem statement

Included in the class box diagram Not as relevant to the problem structure as

associations 21

Identifying Attributes

Page 22: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S22 Object Identification- 2

Descriptive Attributes

Naming Attributes

Referential Attributes

22

Attribute Types

Page 23: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S23 Object Identification- 2

Provide facts intrinsic to each

instance of the object.

– Examples Account.balance, Cat.weight

– If the value of a descriptive attribute

changes, it means only that some aspect

of an instance has changed, but the

instance is still the same instance. 23

Descriptive Attributes

Page 24: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S24 Object Identification- 2

Are used to name or label instances.

– Examples:Account.number, Flight.number

– Names are typically somewhat arbitrary

– Naming attributes are frequently used as an

identifier or part of an identifier.

– If the vale of a naming attribute changes, it means

only that a new name has been given to exactly

the same instance 24

Naming Attributes

Page 25: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S25 Object Identification- 2

Are used to tie an instance of one

object to an instance of another.

– Examples: Cat.owner name indicates which person

owns this cat.

– If the vale of a referential attribute changes, it means

that different instances are now being associated.

25

Referential Attributes

Page 26: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S26 Object Identification- 2

First Rule: One instance of an object or a class has exactly one value

for each attribute at any given time.

26

Rules of Attributes

Employee M/S Phone

M. Fayad 171 4356

G. Smee 23 3456 7890

L. Harris 1234

OK

Not OK

Not OK

[Shlaer-Mellor 90]

Page 27: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S27 Object Identification- 2

Second Rule:

An attribute must contain no internal structure

Examples:

– Age, balance, size are all OK.

– A name consists of first name, middle initial, and last name (Not OK)

– An address contains house number, street name, city, state, zip code, and country name (Not OK) 27

Rules of Attributes (cont’d)

Page 28: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S28 Object Identification- 2

Third Rule: When an object has a compound identifier -- that is, one

made up of two or more attributes -- every attribute that is not part of the identifier represents a characteristic of the entire object.

28

Rules of Attributes (cont’d)

Juice Transfer

storage Tank IDcooking Tank IDgallonsplannedTime

The juice Transfer.gallons attribute means that the number of gallons transferred from the storage tank to the cooking tank and not the number of gallons in either the storage tank or the cooking tank.

Page 29: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S29 Object Identification- 2

Fourth Rule: Each attribute is not part of an identifier that represents

a characteristic of the instance named by the identifier and a characteristic of some other non-identifier attribute

29

Rules of Attributes (cont’d)

Batch

batch IDrecipe IDgallonscookingTime

The Batch.cookingTime attribute mustrepresent the actual time the batch was cooked, and not the cooking time specified by the recipe

Page 30: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S30 Object Identification- 2

Do not keep attributes that have an object as a value, they are associations

Do not keep attributes that depend on a context, these are qualifiers for associations

If an object can have more that one name, then the name qualifies an association of that object with another

30

Eliminating Unnecessary Attributes

Page 31: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S31 Object Identification- 2

Do not put attributes of the association in one or the other of the objects involved in the association, put the attributes in the association itself

Eliminate attributes which are only used internally by the object

Keep initial analysis of attributes at a high level

Eliminate attributes which are too low level

Attributes which are in some instances of a class, but not in others, indicate that the class should be split into two or more classes 31

Eliminating Unnecessary Attributes (cont’d)

Page 32: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S32 Object Identification- 2

Identify classes which share common information

Three basic approaches:

Bottom Up

– Look for classes with repeated associations, attributes or behaviors, and group together into higher level classes

– This approach is easier for inexperienced modelers

Top Down

– Look for Noun phrases describing different kinds of things in the problem statement.

– Examples: Family cars, Sports cars, Luxury cars

Combination of the two approaches works the best.

– Do Top Down when doing initial analysis

– Identify repeated information in the late passes.32

Identifying Inheritance

Page 33: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S33 Object Identification- 2

Always use the “AKO” test

– All inheritance specifications should identify one or more classes which are “A Kind Of” a higher level class.

– NEVER use inheritance for “Part / Part-of” relationships

Use multiple inheritance only when necessary

– Some object-oriented programming languages do not even have this feature.

33

Identifying Inheritance (cont’d)

Page 34: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S34 Object Identification- 2

Done in latest stages

List of behaviors can become large and get detailed quickly.

May correspond to queries about attributes and associations

– Operations to read or write attribute or association value

– Examples: user name, property value, etc.

May correspond to events or activities

– Examples: begin simulation, alert, calculate balance, computer distance 34

Identifying Behaviors

Page 35: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S35 Object Identification- 2

35

Experience and Domain Knowledge

Good objects come from language of domain– If you are not an expert -- consult users

Experience will tune decisions– Slowly at first– Much faster later

Just do it!

Page 36: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S36 Object Identification- 2

• Define with examples: CRC cards, associate objects, referential attributes.

• Describe the third norm for testing objects

• What are the differences between essential objects and accidental objects

• What are questioning techniques and their purposes?

• Describe how do you identify: associations , aggregations, inheritance, attributes, and behaviors

• Describe how to refine objects and associations

• Explain how to define responsibilities and collaborations 36

Discussion Questions

Page 37: L10-S1Object Identification- 2 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department,

2003 SJSU – CmpE -- M.E. Fayad L10-S37 Object Identification- 2

Define:– Type

– Type vs. Class

– Type specifications

– Interface

– Signatures

– Elements of behavior

37

Questions for the Next Lecture