Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-Oriented Analysis

Similar presentations


Presentation on theme: "Object-Oriented Analysis"— Presentation transcript:

1 Object-Oriented Analysis
Barb Ericson Jan 2005 Georgia Institute of Technology

2 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

3 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 What type of thing is each item? For example popcorn is a type of food (or snack). For each snack we would need to know at least the name and price. Georgia Institute of Technology

4 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

5 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

6 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 Customer Maid Room Georgia Institute of Technology

7 Georgia Institute of Technology
CRC Cards Example Clerk Customer Customer Maid Stays in hotel Room Clerk Checks customer in and out Manages maids Maid Room Customer Maid Cleans room Room Clerk Place for customer to stay Georgia Institute of Technology

8 Georgia Institute of Technology
CRC Card Example Clerk Customer Customer Maid Stays in hotel Check in Check out Pay for room Use phone Room Clerk Checks customer in and out Assigns room Handles payment Manages maids Maid Room Customer Maid Cleans room Assigned room Room Clerk Place for customer to stay Georgia Institute of Technology

9 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? Georgia Institute of Technology

10 CRC Card Practice Ideas
Do CRC cards for the movie scenario Do CRC cards for a game of blackjack Do CRC cards for a game of solitaire 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 soccer game Do CRC cards for an ATM Georgia Institute of Technology

11 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

12 Record Class Information
Can use a UML Class Diagram Unified Modeling Language Standard way to documents OO analysis, design, and implementations UML Specification Georgia Institute of Technology

13 Georgia Institute of Technology
UML Tools Popular Tools Rational Rose – Market leader but expensive Visio – Poseidon - Free community edition ArgoUML - Links to sites that list UML Tools is at IBM bought Rational. Georgia Institute of Technology

14 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 By static structure we mean that this structure doesn’t depend on time. Class diagrams can also show packages, objects, and interfaces. Sometimes a class diagram that shows packages is called a package diagram even though in UML it is just a kind of class diagram. Also, a class diagram that shows just objects is sometimes called an Object Diagram even though in UML it is just a kind of class diagram. Georgia Institute of Technology

15 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 Attribute1 Attribute2 size shape Operation1() Operation2() wagTail() bark() Georgia Institute of Technology

16 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. Ocassionally protected is used which subclasses can override Note that the UML definition of these types of visibilities doesn’t always match with the visibilities defined in object-oriented languages. For examples in Java protected means that the item is accessible to objects of the class, objects of any subclasses, and objects of classes in the same package. Georgia Institute of Technology

17 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 Composition is a stronger form of aggregation. It says that the whole must be destroyed if the part is removed and vice versa. Composition implies exclusive ownership. Georgia Institute of Technology

18 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 Georgia Institute of Technology

19 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 An inclusive range includes the values that bound the range. So 0..1 means you can have 0 or 1. The * means many. So 1..* means 1 to many. This can also be expressed as 1*. You can specify multiple multiplicity ranges separated by commas. Georgia Institute of Technology

20 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 A flight will have two airport objects associated with it. It will need to track the airport it is going to and the airport it left from. Georgia Institute of Technology

21 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 The lines between these perspectives are not rigid. Georgia Institute of Technology

22 Georgia Institute of Technology
UML Challenge Draw a class diagram for Solitaire Georgia Institute of Technology

23 Solitaire Class Diagram
Many classes in solitaire are kinds of card piles. You can add cards to card piles and remove cards. The CardPile class is an abstract class (as shown by the italics). The game Klondike has 1 stock, 1 waste, 7 tableaus, 4 foundations, and 1 deck. The game Klondike has 3 option groups. One option group is kings only play for empty tableaus which has two option values, true and false. Another option group is the number of cards to draw from stock. The option values are 1 or 3. The third option group is auto-play which can be either on or off. Georgia Institute of Technology

24 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


Download ppt "Object-Oriented Analysis"

Similar presentations


Ads by Google