Beruflich Dokumente
Kultur Dokumente
A Two-Day Seminar
Michael A. Grasso grasso@cs.umbc.edu http://www.cs.umbc.edu/~mikeg
CSC, Slide 1
Objectives
Module Objective To provide a brief, hands-on overview of object-oriented analysis and design. Topics covered include analysis, design, complementary procedures, and process improvement. In-Class Exercises Case studies based on small project specifications will be used by participants to develop object-oriented models and identify implementation strategies. Module Completion Requirement Participants will be required to demonstrate that they can apply basic object oriented techniques to create and modify object oriented analysis and design models.
CSC, Slide 2
Page 1
References
Software Engineering Software Engineering, 5th Ed., Ian Sommerville, 1995, chapter 14. Coad/Yourdon OOAD Object Oriented Analysis, 2nd Edition, Peter Coad and Ed Yourdon, 1991. Object Oriented Design, Peter Coad and Ed Yourdon, 1991. Object Oriented Programming, Peter Coad and Jill Nicola, 1993. Booch Object Oriented Design Object Oriented Design and Analysis, 2nd Ed., Grady Booch, 1994. Rumbaugh Object Modeling Technique Object Modeling and Design, James Rumbaugh et al., 1991.
CSC, Slide 3
Outline
Section 1. 2. 3. 4. 5. 6. Topic Introduction to OO Object Oriented Analysis Additional Procedures Object Oriented Design Process Improvement Case Studies Slide 5 27 63 82 108 119
About the Instructor Michael Grasso received a doctorate in Computer Science from the University of Maryland Baltimore County in 1997. His research interests include human computer interaction and medical informatics. He has been the Principal Investigator on several research grants sponsored by NIH and DoD. He received a B.S. in Microbiology in 1983 from the University of Maryland at College Park and an M.S. degree in Computer Science from the American University in Washington, DC in 1986.
Object Oriented Analysis and Design CSC, Slide 4
Page 2
Section 1: Introduction to OO
CSC, Slide 5
Page 3
Characteristics of OOAD
Shared data areas are eliminated. Objects communicate by exchanging messages. Reduces the overall system coupling. Objects are independent entities. Changes to implementation of a class should not impact overall system. The separation of external and internal behavior should enhance reuse. Objects can execute either sequentially or in parallel. This is a design decision which can be deferred to later in the design process. For many systems, there is a clear mapping between real-world entities and objects within the system. This improves the understandability of the design.
Object Oriented Analysis and Design CSC, Slide 7
CSC, Slide 8
Page 4
CSC, Slide 9
CSC, Slide 10
Page 5
Structured Analysis
CSC, Slide 11
Data Modeling
The mapping of the problems domain into the following. Entities and Attributes. Relationships. Inheritance. Aggregation. This is a partial solution which is missing specific concepts. Services. Messages. Collaborations. Data Modeling
CSC, Slide 12
Page 6
CSC, Slide 14
Page 7
CSC, Slide 15
CSC, Slide 16
Page 8
Classification
Classification is used to group entities that share common characteristics into a class over which uniform conditions hold.
Objects/Entities Bill 12 Main St. Joe 688 Sun Ct. Sue 155 First St. Instantiate
Classify
CSC, Slide 17
Inheritance
A mechanism for expressing similarity among classes. It portrays generalization (What is the same?) and specialization (What is different?), making common attributes and services explicit within a class hierarchy. Person (Generalize) name address
Bill. 12 Main St. 111-22-3333 $35,000 Sue 155 First St. $1,000
CSC, Slide 18
Page 9
Encapsulation
Encapsulation is the mechanism that binds together code and the data it manipulates and keeps both safe from outside interference and misuse. In the following, only the services move() and scale() modify the attributes of Circle. The service draw() performs some computation based on the values of the attributes.
Polymorphism
Polymorphism is the quality that allows one name to be used for two or more related but technically different purposes. In the following, each graphical object has the same services, although they are implemented differently.
Page 10
Aggregation
Aggregation is used to treat a collection of objects as a single object. For example, among other things, a car consists of tires and an engine. Note that the opposite of aggregation is decomposition.
Car
Tire
Engine
CSC, Slide 21
Association
An association can be viewed as a weak form of aggregation or as a data-oriented relationship between two entities. For example, the following relationship models the concept that if there is a car, it must be associated with an owner.
Owner
Car
CSC, Slide 22
Page 11
Collaboration
Collaboration between classes is achieved though message passing. This documents dependencies between classes by answering the questions. What help do I need? Who needs my help? At some point, class A sends one or messages to class B.
Collaboration Extensions
Flow of messages What messages can I send? What messages can I receive? Here class A sends the getID message to class B. A getId B
Flow of control In what order will messages be sent? These can be further grouped by scenario. For example, scenario A, steps 1 and 2. A.1 A
Object Oriented Analysis and Design
A.2 B C
CSC, Slide 24
Page 12
CSC, Slide 25
Section 1 Exercise
Use some other modeling technique to describe the pH example on the previous slide. You can use PDL, data flow diagrams, flow charts, etc. Prepare a list of objects that you would expect each of the following systems to handle. A program to compute and store bowling scores for a bowling league. A telephone answering machine. A catalog store order entry system. Design a class with encapsulated state and behavior for the following. A linked list. A sorted linked list. A telephone. A bank customer.
CSC, Slide 26
Page 13
These are activities, not sequential steps. However, the activities are introduced in a specific order based on volatility. Services are last, since they are the most volatile. Attributes are next most volatile. Classes and structure are the most stable.
Object Oriented Analysis and Design CSC, Slide 27
Page 14
Possible OO Diagrams/Views
These may be on separate diagrams or part of the same diagram. Class Diagram. A graph which shows the static structure of the model. Includes classes, class structure (attributes and operations), and class relationships (inheritance, aggregation, associations). Object Diagram, A graph of class instances. Includes objects, object states, and object collaborations. May be static and show a snapshot of system state at a point in time. May be dynamic and show how system state changes over a period of time. Other diagrams are covered elsewhere. DFD, ERD, STD, etc.
Object Oriented Analysis and Design CSC, Slide 29
Activity 1: Classes
Class A description of a group of objects with a uniform set of properties. Classes may be further defined as any of the following. Abstract. A class with no instances, but whose descendants may have instances. Concrete. A class that can be instantiated. A class is assumed to be concrete, unless otherwise stated. Object An object is an instatiated class or an abstraction of something within the problem domain.
CSC, Slide 30
Page 15
Notation
name attributes
services
services
Class
Abstract Class
Object
CSC, Slide 31
Naming Classes
Naming alternatives. Singular noun. e.g. Clerk. Adjective and noun. e.g. NewAccountsEmployee. Vocabulary. Choose name using the standard vocabulary for the subject matter. For example, in a library system choose the name Borrow over the name CheckOutEvent. Use readable names. Capitalize the first letter of each word. Do not add prefix or suffix codes.
CSC, Slide 32
Page 16
Finding Classes
Nouns Persons, places, and things in the problem domain. Previous OOA Results. The previous OOA results of similar systems. Structures. Inheritance and aggregation. This is an activity in itself and will be discussed later. Other Systems. Other systems or external entities the system will interact with. Devices. Devices the system will need to interact with. Defer implementation-specific computer components until design.
Object Oriented Analysis and Design CSC, Slide 33
Finding Classes
Things or Events Remembered. Historical events that must be observed and recorded by the system. Normally and event would just be modeled as a service. event = service Here we are modeling the fact that an event happened at a particular time. event + date = event remembered class Sites. Physical locations the system needs knowledge of. Organizational Units. Organizational units the humans in the system belong to, such as within a company or country.
CSC, Slide 34
Page 17
Finding Classes
Roles Played. The roles played by human beings in the system. Distinct groups of people with specific attributes and services. Notes on human interaction. Since humans can be thought of as interacting with the entire model. Therefore, place these classes in the OOD Human Interaction Component. However, if one desires, this interaction can be placed in the OOA model, although this is not Coad and Yourdon's preference. Operational Procedures. Operational procedures the system has to hold to over time, such as work-flow steps that are not inherent in the problem domain constraints.
CSC, Slide 35
CSC, Slide 36
Page 18
CSC, Slide 37
Inheritance
Inheritance is also called the generalization-specialization, gen-spec, or IsA hierarchy. Note that inheritance is a relationship between classes, not objects. Generalized classes are placed higher in the hierarchy while specialized ones are found below. For example, a Vehicle is a generalized class while TruckVehicle and CarVehicle are more specialized ones. In other words, a TruckVehicle is-a-kind-of Vehicle.
CSC, Slide 38
Page 19
Inheritance Notation
Inheritance hierarchy. The generalized class at the top and the specialized classes below. The specialized class names should reflect the class they were specialized from. For example, ClerkPerson was specialized from Person.
Person
Employee
Customer
CSC, Slide 39
Inheritance Strategy
Consider each class as a generalization and apply the following criteria against specializing it. Is it in the problem domain? Would the new class have relevance? Is it within the system's responsibility? Does the system need to recognize the difference between a specialized and generalized version of the class? Will there be inheritance? Will the specialized class meet the criteria for classes? In a similar fashion, consider each class as a specialization and apply the same criteria against generalizing it.
Object Oriented Analysis and Design CSC, Slide 40
Page 20
Airport
Aircraft
Shipment Item
CSC, Slide 41
Inheritance Hierarchy
Most inheritance structures take the form of a tree or hierarchy.
Vehicle
CarVehicle
TruckVehicle
TrailerVehicle
CSC, Slide 42
Page 21
Inheritance Lattice
Some inheritance structures take the form of a lattice instead of a hierarchy.
Person
Clerk
Customer
CustomerClerk
CSC, Slide 43
Clerk
Customer
CustomerClerk
CSC, Slide 44
Page 22
Aggregation
Aggregation is also called whole-part or HasA. For example, an Aircraft contains an Engine or in other words, an Aircraft has an Engine. Note that this relationship can be quantified in one of two ways, depending on how the relationship is viewed. As a relationship between objects. As a relationship between classes. The approach you use will depend on the methodology you choose. Note that inheritance was viewed as a relationship between classes.
CSC, Slide 45
CSC, Slide 46
Page 23
CSC, Slide 47
Aggregation as Attributes
Both aggregation and associations can also be modeled using attributes. This is covered in more detail under OOD.
Aircraft Engine[4]
Aircraft CargoItem[m]
CSC, Slide 48
Page 24
Aggregation Strategy
When looking for potential aggregation structures, consider the following. Assembly-Parts. An Aircraft is an assembly with Engine(s) as parts. Container-Contents. An Aircraft is a container with CargoItem(s) as its contents. Collection-Members. An Company is a collection with Employee(s) as its members. Associations or Object Connections. An alternative to the aggregation structure is the association, which is sometimes called a weak has-a.
CSC, Slide 49
Associations
Responsibilities. An association is used to identify that one object needs another in order to fulfill its responsibilities. Associations. Associations reflect associations between objects. Dependencies. You can also view associations as instantiation dependencies. For example, if an object of class A is instantiated, then an object of class B must be instantiated. Weak has-a. It is sometimes called a weak has-a, and can be used in place of aggregation when such a structure does make sense conceptually.
CSC, Slide 50
Page 25
Association Strategy
For each object or class. Identify associations and dependencies within the problem domain and the system's responsibilities. If necessary, the associations can be labeled. Quantify associations, similar to aggregation. A one-to-many association between the Customer and Invoice classes. Customer 1 Purchase m Invoice
Purchase 1 Invoice
CSC, Slide 51
Many-to-Many Associations
Check for many-to-many associations. This may reflect the need for an event remembered class as an intermediary. Unless otherwise specified all quantification is between objects.
Owner
m m
Vehicle
Owner
m 1
Registration
1 m
Vehicle
CSC, Slide 52
Page 26
Multiple Associations
Check for multiple associations between objects. This may reflect the need for an event remembered class.
Register Title
Owner
Vehicle
CSC, Slide 53
CSC, Slide 54
Page 27
Activity 2: State
Object states. An attribute is data for which each object in a class has a value. Attribute manipulation. Attributes are only manipulated by the services of that object. Volatility. Attributes are more likely to change than classes. Atomic concepts. Each attribute should capture an atomic concept - either a single value (such as a social security number) or a tightly related grouping of values (such as a mailing address).
CSC, Slide 55
Attribute Strategy
When identifying attributes, answer the following questions from the perspective of a single object. What do I need to know? What states can I be in? How am I described in general or in the problem domain? Put each attribute in the class which it best describes. Most often this is straight forward. In some instances, an attribute may be shared by more than one class. In this case, attempt to identify which class the attribute is really describing. Make sure each attribute contributes to the single purpose of its class.
CSC, Slide 56
Page 28
CSC, Slide 57
Activity 3: Behavior
Behaviors of a class are also call functions, operations, or services. Identify the object states. Every change in the attribute values of an object reflects a change in the object's state that, in turn, reflect a change in object behavior. Identify the required behaviors. What is the object suppose to do? Make sure each service contributes to the single purpose of its class. All objects have the following implicit behaviors that are not explicitly shown in the OOA model. create: create a new object. connect: connect/disconnect an object from another. access: get/set the attribute values of an object. release: disconnect and delete an object.
Object Oriented Analysis and Design CSC, Slide 58
Page 29
Activity 4: Collaborations
Message connections model the processing dependency of an object, indicating a need for services in order to fulfill its responsibilities. The message connection maps one object to another, in which a sender sends a message to a receiver. The receiver performs some processing and returns the results to the sender. Alternatively a message connection is sent to a class to create a new object. Message connections exist solely for the benefit of the services. To identify needed message connections, ask the following of each object. What other objects does it need services from? What other objects need one of its services?
Object Oriented Analysis and Design CSC, Slide 59
CSC, Slide 60
Page 30
Collaboration Example
In the following, a print queue sends a message to a printer telling it to print a particular print job. The message connections are part of a critical thread of execution, showing their relative order of execution.
m (A.1) 1 PrintJob
(A.2) 1 1
CSC, Slide 61
CSC, Slide 62
Page 31
CSC, Slide 63
Subjects
Subjects used give an overview of a larger OOA model. They can be formalized subsystems with their own behavior or informal grouping to increase understanding. Subjects are created by following steps. Collapse the structure by promoting the uppermost class in each structure to a subject item. Make all remaining classes not in structures subject items. Refine the subjects by combining items in related sub-domains. Further refine the subjects by combining objects to minimize interactions between subjects.
CSC, Slide 64
Page 32
Subject Notation
Use one of three notations in the subject layer. Draw a large rectangle around each subject in the OOA diagram, without simplifying the structure. Use a class-like notation to show subjects and the names of the classes in each subject. Show only subject names. All three can be used at the same time to show different subjects in various levels of detail. Subject 1 Subject 1 C1 C2 C3 Class 1 Class 2 Class 3 Subject 1
Subject 2
CSC, Slide 65
Secondary Diagrams
Object Oriented Analysis is a methodology that is based on classes. However, this does not mean other models cannot be used. The difference is that these other models are secondary and that classes are the foundation of the design. Booch, Rumbaugh, Coad, and Yourdon all use secondary models in their respective methodologies. Although, each emphasize these models in different ways. Some common secondary diagrams include the following. State transition diagrams. Data flow diagrams. Service charts. Flow charts.
CSC, Slide 66
Page 33
Transition Events/Actions
CSC, Slide 68
Page 34
CSC, Slide 69
Page 35
Process
Data Flow
Actor
Data Store
CSC, Slide 71
User
job
CSC, Slide 72
Page 36
CSC, Slide 73
Domain Analysis
Domain analysis seeks to identify the classes and objects that are common to all applications of a given domain. For example: all accounting systems have certain classes in common. Domain analysis works well, because there are very few truly unique kinds of software systems. Try to compare the system you are developing to a generalized class of systems. When starting to design a system. Survey the architecture of existing systems in that domain. Define key abstractions and mechanisms. Evaluate which can be used in the new system. A domain expert may be required to assist in this effort.
CSC, Slide 74
Page 37
Use-Case Analysis
Use-case analysis was first formalized by Jacobson [I. Jacobson, et al. 1992. Object-Oriented Software Engineering., Addison-Wesley]. A use case is a scenario that begins with some user of the system initiating some transaction or sequence of interrelated events. Scenario planning of this type is employed by many other OO methodologies, including Coad/Yourdon, Jacobson, and Wirfs-Brock. A basic scenario planning approach is introduced under human interaction in the section on design. Basic goal is to group the primary function points of the system by related behavior or hierarchy. This technique is similar to storyboarding. A common in the television and movie industry. In it's simplest form, it consists of post-its, magic markers, and a white board.
Object Oriented Analysis and Design CSC, Slide 75
CSC, Slide 76
Page 38
CRC Cards
CRC cards were first proposed by Beck and Cunningham [K. Beck, W. Cunningham. October 1989. A Laboratory for Teaching ObjectOriented Thinking, SIGPLAN Notices, 24(10)]. CRC stands for Class - Responsibility - Collaboration. They are simple 3x5 index cards with the class name along the top and two columns below for responsibilities and collaborations. They provide a simple tool for team development tasks, such as storyboarding. They can be used during storyboarding sessions to keep track of the classes for each scenario. They can be easily grouped and organized.
CSC, Slide 77
Informal English
An alternative is to write an English language description of the problem, or part of the problem. [R. Abbot. November 1983. Program Design by Informal English Descriptions. Communications of the ACM, 26(11)] Take the natural language description and underline the nouns and verbs to identify candidate classes and operations, respectively. This is by no means a rigorous approach. Natural language is to imprecise and ambiguous. Any noun can be verbed, and any verb can be nouned. However, since natural language is often used for system descriptions and requirements documents, it may provide some useful insight.
CSC, Slide 78
Page 39
Service Documentation
Document the services within each class. Identify the following for each service: parameters, external input, external output, additional constraints, and notes. Services can be further documented using PDL, an object state diagram, a service chart, a flow chart, data flow, state-transition diagram, etc. Critical threads of execution spanning one or more classes can also be documented by numbering the corresponding message connections and adding additional annotations or diagrams. Don't hesitate using functionally-oriented notations to document services. In this limited context they can be very useful. You just don't want to use this approach to drive the OOA model.
CSC, Slide 79
OOA Documentation
Along with the OOAD model, additional documentation includes the class specification template. Class specification template Class Name and description Object state diagram Attributes Name, type, and description Services Name and prototype PDL, flowchart, dataflow diagram or service chart External inputs and outputs Additional constraints Pre- and post-conditions, invariants, axioms Other documentation, as needed
Object Oriented Analysis and Design CSC, Slide 80
Page 40
CSC, Slide 81
CSC, Slide 82
Page 41
CSC, Slide 83
CSC, Slide 84
Page 42
Add Implementation-Specific Components Human interaction Data management Other implementation areas
CSC, Slide 85
CSC, Slide 86
Page 43
CSC, Slide 87
CSC, Slide 88
Page 44
CSC, Slide 90
Page 45
CSC, Slide 91
CSC, Slide 92
Page 46
CSC, Slide 93
HIC Strategy
Classify humans and describe their task scenarios. Identify the types of humans who will use the system. Describe their needs and what they need the system to do for them. This approach is similar to Use-Case Scenarios. Design the command hierarchy for human interaction. Menu screens or bars. A series of icons. A command line. Design the HIC Classes. Create the classes necessary to support human interaction. Types include menu, input, and display classes. Prototyping the human interface Allow user community to experience, play with, and refine the proposed human interface.
Object Oriented Analysis and Design CSC, Slide 94
Page 47
CSC, Slide 95
0,m 1 Field
0,m 1 DisplayBox
0,m 1 Menu
CSC, Slide 96
Page 48
Window
NewCustWindow
DeleteCustWindow
CSC, Slide 97
CSC, Slide 98
Page 49
Page 50
Page 51
0,1
Customer
Page 52
Aggregation nested struct none Association Attribute Service Message pointer none
C++ Example class Stack { char *v; int sz; public: Stack(int size); ~Stack(); void push(char c); char pop(); }; main() { Stack s1(10); Stack s2(25); ... }
Page 53
Software Crisis. Process Maturity. Implementing OO. OO Vendors, Methodologies, and Tools. Refer to IEEE Computer Special Issue on Managing Object-Oriented Software Development, 29(9), September, 1996, for more information.
Page 54
A Software Crisis
A 1979 GAO report (FGMSD-80-4, 11/79) evaluated 7 million dollars worth of software development projects and discovered that as a percentage of cost: 47% were never used 29% were never delivered 19% required extensive reworking or were abandoned 3% required additional modifications 2% met its requirements Tom DeMarco pointed out in 1982 that 25 percent of large system development projects never finish. (Controlling Software Projects, Prentice Hall, 1982) Capers Jones documented in 1991 the gloomy statistic that the average MIS development project is one year late and 100 percent over budget. (American Programmer, 6/91)
Object Oriented Analysis and Design CSC, Slide 109
Page 55
Analysis Challenges
Problem Domain Understanding To design an accounting system, an analyst needs to become an expert in accounting systems, and will probably need to understand these systems better than the average user will. Person-To-Person Communication It is very difficult for people from different perspectives to share ideas with each other. For example, an analyst and a user, or a manager and a worker. Continual Change Requirements will change. Your designs need to account for change and should attempt to minimize their effect. Reuse Reuse of code as well as design and analysis results.
Object Oriented Analysis and Design CSC, Slide 111
Page 56
Project Management
Your first OO application will take longer. Expect at least 25% longer. There is a learning curve associated with adopting OO. More of the total effort will be spent in analysis and design. Expect about 60% of the total effort. Class design is an iterative process. Spiral approach. Radical waterfall approach. Evolutionary approach.
Page 57
More on Moving to OO
Selecting the First Project. A new system with clean interfaces and little legacy code. Large enough to be meaningful, but small enough to handle. Support from senior management. Why OO Projects Fail. Expect OO technology to solve preexisting problems within a groups development process or culture. Not sure how to manage transition to new technology. Project management defering to programming team on management issues, because of new technology.
Page 58
http://www.rational.com/
Page 59
Page 60
OOA Model
Use the basic class/state/behavior/collaboration OOA notation to describe the OOA notation itself. This might be necessary, for example, if you were to develop a case tool that supported this approach. Hints: Start out by listing every concept in the notation, such as attributes and whole-part structures. Build structures from these concepts. For example, a class has attributes. Add support for secondary models and documentation, such as subjects and data flow diagrams.
Page 61
...
m 1 connect Media id title subject store retrieve Not shown are whole-part connections from LibraryContainer to all other classes.
retrieve, checkIn, store Borrow id checkOutDate checkInDate borrowerId mediaId checkOutMedia checkInMedia store retrieve
m connect
type is faculty or student checkOutMedia(borrowerName, mediaTitle) send getBorrowerId message to borrower send getMediaId message to media set checkOutDate to system date checkInMedia() set checkInDate to system date Borrow::retrieve(borrowerName, mediaTitle) Borrow::retrieve(id) retrieve borrow from database based on id or name and title
(A.1)
0,m (A.2)
1 WidgetDescription SalesTransactionItem name m quantity size 1 actualCost color (A.4) cost calculateCost amountInStock updateWidget amountOnOrder reorderLevel adjustInventory reorder makePO
Page 62
Graphics Library
ShapeContainer paint 0,m 1 paint 1 GraphicDevice (Abs) xLen yLen init [abs] restore [abs] drawPoint [abs] drawRectangle [abs] drawCircle [abs]
1 Shape (Abs) color draw [abs] move 1 0,1 Location x y Point draw Circle radius draw scale
draw
OOA Model
Subject name desc connect_type = inheritance, aggregation, association, message class_type = concrete, abstract data_type = integer, string, etc. diagram_type = dfd, erd, std, etc.
m m Class name desc class_type m m 1 Service name desc prototype m Diagram name desc diagram_type m m m
parent
child
Page 63