georgia institute of technology object-oriented analysis barb ericson [email protected] june...

27
Georgia Institute of Technology Object-Oriented Analysis Barb Ericson [email protected] June 2006

Upload: jake-heaphy

Post on 15-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Object-Oriented Analysis

Barb Ericson

[email protected]

June 2006

Page 2: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Learning Goals

• Understand at a practical level– How to identify objects and classes– How to record potential classes– How to record responsibilities– How to record fields and methods– How to record the relationships between

classes

Page 3: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Objects and Classes

• To write an object-oriented program we need to identify the objects that we need to create– And determine how to classify them

• What data does an object need to keep about itself? These are the fields.

• What things should an object be able to do? These are the methods.

• Next we write a class for each classification of the needed objects

Page 4: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Identifying Classes

• As you go through a scenario– Write down each noun you hear (or underline

each noun if the scenario is written)– Put each one at the top of an index card– Write down what objects of this class are

responsible for– Write down what other classes this object has

to work with to accomplish it’s responsibilities

Page 5: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

CRC Cards

• Class Responsibility Collaborators

• Developed by Ward Cunningham and Kent Beck at Tektronix in the late 1980’s

• Analysis technique

Classname

Responsibilities Collaborators

Page 6: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Use and Advantages

• Used to– Record classes as they are identified– Record the purpose (responsibility) of each

class– Record and experiment with relationships

(collaborators) between classes

• Advantages– cheap, portable, readily available, and familiar– focus on analysis, not on a diagram– good in a group discussion

Page 7: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

CRC Cards Example

• Do an analysis of a hotel room reservation system. – The system must allow clerks to assign rooms to

customers. It must also allow clerks to assign maids to clean the rooms.

Clerk

Maid

Customer

Room

Page 8: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

CRC Cards ExampleClerk

Checks customer in and out

Manages maids

Customer

Maid

MaidCleans room Room

Clerk

CustomerStays in hotel Room

Clerk

RoomPlace for customer to stay

Customer

Maid

Page 9: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

CRC Card ExampleClerk

Checks customer in and out

Assigns room

Handles payment

Manages maids

Assigns room

Customer

Maid

MaidCleans room

Assigned room

Cleans room

Room

Clerk

CustomerStays in hotel

Check in

Check out

Pay for room

Use phone

Room

Clerk

RoomPlace for customer to stay

Customer

Maid

Page 10: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Abstraction

• Pull out only the important details about the thing we are simulating– Maids have hobbies but we don’t need to

know about them

• What is important in the context of the problem?– What data will objects of the class need– What things will they need to be able to do?

Page 11: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Analysis of Selling Items on a Web Site

• We want to sell items on a web site and we need to keep track of our customers and their orders– Create CRC cards for this

• Do a walk through of placing an order– Did you find any new objects, data, or

methods that you might need?

• It can help to look at some sample web sites like amazon.com

Page 12: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

CRC Card Practice Ideas

• Do CRC cards for a game of battleship

• Do CRC cards for a game of blackjack

• Do CRC cards for a game of war

• Do CRC cards for a drawing program

• Do CRC cards for airplane flights

• Do CRC cards for a bookstore website

• Do CRC cards for an ATM

Page 13: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Drawing Editor Exercise

• Identify the classes for a simple drawing editor. Also show the data and operations for the classes. – The editor can draw rectangles, circles, and triangles.

It can show connections between shapes with a a line. The shapes can be erased, moved, and rotated.

Page 14: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Record Class Information

• Can use a UML Class Diagram– Unified Modeling Language

• Standard way to documents OO analysis, design, and implementations

• UML Specification – http://www.omg.org/technology/documents/

formal/uml.htm

Page 15: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

UML Tools

• Popular Tools– Rational Rose – http://www.rational.com

• Market leader but expensive

– Visio – http://www.microsoft.com/office/visio – Poseidon - http://www.gentleware.com/

• Free community edition

– ArgoUML - http://argouml.tigris.org/– Links to sites that list UML Tools is at– http://www.omg.org/technology/uml/index.htm

#Links-Methodologies

Page 16: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Class Diagram

• Shows classes and the relationships between them – Static structure

• Not time dependent

• Most important and commonly used diagram in UML

Page 17: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Class Representation

• Rectangles are used to represent classes

• There are different sections for the class name, attributes and operations

Class Name

Attribute1Attribute2

Operation1()Operation2()

Dog

sizeshape

wagTail()bark()

Page 18: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Visibility

• Who can access the item• Types of Visibility

– Public (+)• All can use

– Private (-)• Only objects of the class

• Attributes should be private– So the object has control of its’ data

• Methods are public or private– Public if intended as a service. Private if for internal use.

Occasionally protected is used which subclasses can override

Page 19: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Static Class Relationships

• Association– has-a – A connector has shapes

• Generalization– is-a-kind-of – A circle is a kind of shape

• Aggregation– is-a-part-of– A display list is an

aggregation (collection) of shapes

Page 20: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Dynamic Class Relationship

• Dependency– Uses– A car uses a parking

space– It doesn’t have a have-

a relationship with it

• Dynamic relationships are relationships that change over time

Page 21: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Association Multiplicities

• Associations have multiplicities (one for each end)– X can have how many objects of y associated with it?– Y can have how many objects of x associated with it?

• Kinds of Multiplicities– m..n

• Inclusive range from m to n

– n• There must be exactly n

– * or 0..*• 0 to many

Page 22: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Roles

• Each association end is a role– role A– role B

• Roles can be explicitly named– Especially useful when

there is more than one association between the classes

– Or for use in generated code

Page 23: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Class Diagram Perspectives

• There are three perspectives that a class diagram can represent– Conceptual - Analysis Stage

• Language independent, represents the domain

– Specification - Design Stage• Represents a high level design of the solution

– Implementation – Programming Stage• Represents the actual solution• Shows attributes, operations, types (if needed),

and parameters to operations

Page 24: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Bingo Exercise

• What objects are there in Bingo?– What data do these objects have?– What things can they do?– How do you classify them?

• For each class in Bingo– What is the relationship with the other

classes?

• Draw a UML diagram for a Bingo Game

Page 25: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

UML Challenge

• Draw a class diagram for Solitaire

Page 26: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Solitaire Class Diagram

Page 27: Georgia Institute of Technology Object-Oriented Analysis Barb Ericson ericson@cc.gatech.edu June 2006

Georgia Institute of Technology

Summary• In Analysis you need to understand the objects

in the domain (“real world”)• Figure out what the objects are responsible for

– What data do they need to have?– What things can they do?

• UML class diagrams show lots of information in a picture– Can be helpful on exam questions

• About inheritance and polymorphism

• Determine the relationships between the classes– Has a (association)– Is a type of (inheritance)