ObjectOriented Analysis Barb Ericson ericsoncc gatech edu June
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 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 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 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 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 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 clerks to assign maids Clerk customers. It must also allow Customer to clean the rooms. Maid Room Georgia Institute of Technology
CRC Cards Example Clerk Checks customer in and out Customer Stays in hotel Maid Room Clerk Manages maids Maid Cleans room Room Clerk Place for customer to stay Georgia Institute of Technology Customer Maid
CRC Card Example Clerk Checks customer in and out Customer Maid Stays in hotel Check in Assigns room Check out Handles payment Pay for room Manages maids Room Clerk Use phone Assigns room Maid Cleans room Assigned room Room Clerk Place for customer to stay Cleans room Georgia Institute of Technology Customer Maid
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? 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 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 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. 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/for mal/uml. htm 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 – Argo. UML - http: //argouml. tigris. org/ – Links to sites that list UML Tools is at – http: //www. omg. org/technology/uml/index. htm #Links-Methodologies 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 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 Dog Attribute 1 Attribute 2 size shape Operation 1() Operation 2() wag. Tail() bark() 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. Georgia override 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 Georgia Institute of Technology
Dynamic Class Relationship • Dependency – Uses – A car uses a parking space – It doesn’t have a havea relationship with it • Dynamic relationships are relationships that change over time 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 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 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 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 Georgia Institute of Technology
UML Challenge • Draw a class diagram for Solitaire Georgia Institute of Technology
Solitaire Class Diagram 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) Georgia Institute of Technology
- Slides: 27