Chapter 18 Object-Oriented Systems Analysis and Design Using UML Kendall & Kendall Sixth Edition
© 2005 Pearson Prentice Hall Major Topics Object-oriented concepts and terminology CRC Cards Unified Modeling Language Use case and other UML diagrams Relationships Kendall & Kendall © 2005 Pearson Prentice Hall
Object-Oriented Overview Object-oriented (o-o) techniques work well in situations where complicated systems are undergoing continuous maintenance, adaptation, and design. The Unified Modeling Language (UML) is an industry standard for modeling object-oriented systems. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Goals of O-O Analysis Reusability is the main goal. Maintaining systems is an important goal. Making a change in one object has a minimal impact on other objects. Kendall & Kendall © 2005 Pearson Prentice Hall
Object-Oriented Concepts Definitions and concepts: An object, represents a real-world thing or event. Objects may be customers, items, orders and so on. Objects may be GUI displays or text areas on a display. Kendall & Kendall © 2005 Pearson Prentice Hall
Object-Oriented Concepts Definitions and concepts (continued): Objects are represented by and grouped into classes. A class, or group of related objects has a set of shared attributes and behaviors. Instantiate is a term used when an object is created from a class. Attributes are properties of a class possessed by all objects. A method is an action that can be requested from any object in the class. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Class Symbol Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Inheritance Inheritance is when a new class is created from another class. The original class is the parent or base class. The new class is the child or derived class. The child class receives the attributes and methods of the parent class. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall CRC Cards Class, responsibilities, and collaborators (CRC) cards are used to represent the responsibilities of classes and the interaction between the classes. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Creating CRC Cards Analysts create CRC cards by: Finding all the nouns and verbs in a problem statement. Creating scenarios that are actually walkthroughs of system functions. Identifying and refining responsibilities into smaller and smaller tasks, if possible. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Creating CRC Cards Analysts create CRC cards by (continued): Determining how tasks are fulfilled by objects or interact with other things. Identifying responsibilities that evolve into methods or operations. Kendall & Kendall © 2005 Pearson Prentice Hall
The Unified Modeling Language (UML) UML has three categories: Things, the objects. Relationships, the glue that holds things together. Diagrams, categorized as either structure or behavioral. Kendall & Kendall © 2005 Pearson Prentice Hall
Two General Groupings of Things There are two general groupings of things in UML: Structural things that define the conceptual and physical structures of an O-O system and are described by nouns. Behavioral things, the verbs of a UML model that represent the behavior of the system and the states of the system before, during, and after the behaviors occur. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Structural Things Structural things are the most common and include: Classes. Use cases. Interfaces. Kendall & Kendall © 2005 Pearson Prentice Hall
Behavioral Things/Diagrams Behavioral things include: Interactions. State machines. Kendall & Kendall © 2005 Pearson Prentice Hall
Types of Relationships There are two types of relationships that hold things together: Structural relationships tie things together in structural diagrams. Behavioral relationship are used in behavioral diagrams. Kendall & Kendall © 2005 Pearson Prentice Hall
Structural Relationships Structural relationships are: Dependencies. Aggregations. Associations. Generalizations. Kendall & Kendall © 2005 Pearson Prentice Hall
Behavioral Relationships Behavioral relationships are: Communicates. Includes. Extends. Generalizes. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Structural Diagrams Structural things are the most common and include: Class and object diagrams. Use case diagrams. Component diagrams. Deployment diagrams. Kendall & Kendall © 2005 Pearson Prentice Hall
Behavioral Things/Diagrams Behavioral things include: Use case diagrams. Sequence diagrams. Collaboration diagrams. Statechart diagrams. Activity diagrams. Kendall & Kendall © 2005 Pearson Prentice Hall
Commonly Used UML Diagrams The most commonly used UML diagrams are: Use case diagram, describing how the system is used. The starting point for UML modeling. Use case (not a diagram). Activity diagram. Each use case may create one activity diagram. Kendall & Kendall © 2005 Pearson Prentice Hall
Commonly Used UML Diagrams The most commonly used UML diagrams (continued): Sequence diagram, showing the sequence of activities and class relationships. Each use case may create one or more sequence diagrams. A collaboration diagram is an alternative to a sequence diagram. Kendall & Kendall © 2005 Pearson Prentice Hall
Commonly Used UML Diagrams The most commonly used UML diagrams (continued): Class diagram, showing classes and relationships. Sequence diagrams and CRC cards are used to determine classes. Statechart diagram. Each class may create a statechart diagram, useful for determining class methods. Kendall & Kendall © 2005 Pearson Prentice Hall
Overview of UML Diagrams Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Use Case Diagram A use (yoos) case describes what the system does, not how it does the work. The use case model reflects the view of the system of the user outside of the system. Symbols are: Actor, a stick figure. Use case, an oval. Connecting lines. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Actors Represent role played by one or more users Exist outside of the system May be a person, another system, a device, such as a keyboard or Web connection Can initiate an instance of a use case May interact with one or more use cases and a use case may involve one or more actors Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Actors (Continued) Actors may be divided into two groups: Primary actors supply data or receive information from the system Secondary actors help to keep the system running or provide help Help desk, analysts, programmers, etc. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Use Case Consists of three things: An actor (user) that initiates an event. An event that triggers a use case. The use case that performs the actions triggered by the event. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Use Case (Continued) Better to create fewer use cases 20 use cases for a large system 50 use cases would be the maximum for a large system Can nest use cases, if needed Kendall & Kendall © 2005 Pearson Prentice Hall
Use Case Relationships Communicates Connect an actor to a use case Includes Use case contains a behavior that is common to more than one use case. The common use case is included in other use cases. Dotted arrow points toward common use case. Kendall & Kendall © 2005 Pearson Prentice Hall
Use Case Relationships (Continued) Extends A different use case handles variations or exceptions from the basic use case. Arrow goes from extended to basic use case. Generalizes One thing is more general than another thing. Arrow points to the general thing. Kendall & Kendall © 2005 Pearson Prentice Hall
Use Case Relationships Kendall & Kendall © 2005 Pearson Prentice Hall
Steps for Creating a Use Case Model The steps required to create a use case model are: Review the business specifications and identify the actors within the problem domain. Identify the high-level events and develop the primary use cases that describe the events and how actors initiate them. Kendall & Kendall © 2005 Pearson Prentice Hall
Steps for Creating a Use Case Model The steps required to create a use case model are (continued): Review each primary use case to determine possible variations of flow through the use case. Develop the use case documents for all primary use cases and all important use case scenarios. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Use Case Scenario A use case scenario may be created for the standard flow through the use case. Other scenarios may be created for variations on the main flow. A use case includes: Use case identifiers and initiators. Steps performed. Conditions, assumptions, and questions. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Activity Diagrams Activity diagrams show the sequence of activities in a process, including sequential and parallel activities. Symbols are used for activities, decisions and so on. Arrows represent events that connect the activities. Kendall & Kendall © 2005 Pearson Prentice Hall
Activity Diagram Symbols Kendall & Kendall © 2005 Pearson Prentice Hall
Creating Activity Diagrams Ask what happens first, second, and so on. Determine if the activities happen in sequence or parallel. Examine all the scenarios for a use case. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Swimlanes Included on activity diagrams to show partitioning Show which activities: Occur on a browser Occur on a server Happen on a mainframe Are done by external partners Help to divide tasks among team members Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Swimlane Boundaries When an event crosses swimlane boundaries, data must be transmitted. A Web form is sent to a server. Data are placed into middleware to transmit it between a server and a mainframe. Data are transmitted to and from an external partner. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Sequence Diagrams Sequence diagrams show a succession of interactions between classes or object instances over time. It also shows the processing described in a single scenario. The leftmost object is the starting object. Time sequence is from top to bottom. Kendall & Kendall © 2005 Pearson Prentice Hall
Sequence Diagrams (Continued) Horizontal arrows represent messages or signals sent between classes. Solid arrowheads represent synchronous calls, the sending class waits for a response. Half or open arrowheads represent asynchronous calls, those sent without waiting for a returning signal. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Message Name Formats Message names may be in the following formats: messageName() messageName(parameter1, parameter2, …) messageName(parameterType:parameterName)(defaultValue) Kendall & Kendall © 2005 Pearson Prentice Hall
Sequence Diagram Example Kendall & Kendall © 2005 Pearson Prentice Hall
Collaboration Diagrams Collaboration Diagrams show the same information as a sequence diagram. The emphasis is on the organization of the objects. Sequence is shown by including a sequence number on the message. Kendall & Kendall © 2005 Pearson Prentice Hall
Collaboration Diagram Example Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Class Diagrams Class diagrams show classes, attributes, and operations or methods. A class is shown as a rectangle. Kendall & Kendall © 2005 Pearson Prentice Hall
Class Diagram Attributes Attributes are either: Private (the norm), indicated by a minus sign. Public, indicated by a plus sign. Protected, indicated by a pound sign (#). Attributes may include the type of data and any initial value. Methods are usually public. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Method Overloading Method overloading is including the same method several times in a class. The method signature, its name and parameters, and type of parameters, must be different. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Types of Classes Classes fall into several categories: Entity classes. Boundary or interface classes. Abstract classes. Control classes. Each class may use a special symbol, called a UML stereotype. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Entity Classes Entity classes represent real-world items. Attributes are those stored for the entity. Methods work with the entity. Kendall & Kendall © 2005 Pearson Prentice Hall
Boundary or Interface Classes Provide a means for users to work with the system. Display screens, windows, dialogue boxes, touch-tone telephone, external systems. Methods required to send or reset the display screen, or to produce a report. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Abstract Classes Abstract classes are the parent or general class in a generalization/specialization relationship. Abstract classes may not be directly instantiated. Only the child classes can create objects. Kendall & Kendall © 2005 Pearson Prentice Hall
Control or Active Classes Control or active classes are used to control the flow of activities. Many small control classes may be included to achieve reuse. Attributes are those needed temporarily by the control class. Methods are those used in control activities . Kendall & Kendall © 2005 Pearson Prentice Hall
Sequence Diagram Example Using Class Stereotype Symbols Kendall & Kendall © 2005 Pearson Prentice Hall
Relationships on a Class Diagram Relationships are the connections between classes and include: Associations, showing the one-to-many relationships between classes. An asterisk (*) is used to represent many. Association classes are used to break up a many-to-many association between classes. Kendall & Kendall © 2005 Pearson Prentice Hall
Association Class Example Kendall & Kendall © 2005 Pearson Prentice Hall
Whole/Part Relationships One class represents the whole, other classes represent the parts contained in the whole. Three types of whole/part relationships: Aggregation. Collection. Composition. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Aggregation Aggregation is a “has a” relationship. The whole is composed of the sum of the parts. If the whole is removed, the part may still exist. The diamond at the end of the line is not filled in. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Collection Consists of a whole and its members Examples are a library with books or a voting district with voters If the part is removed, the whole retains its identity A weak association Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Composition The whole has a responsibility for the parts, and is a stronger relationship. If the whole is removed, the parts are removed Shown with a filled-in diamond on the line Example: an insurance policy with riders Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Whole/Part Example Kendall & Kendall © 2005 Pearson Prentice Hall
Generalization/Specialization Diagrams Generalization/specialization or gen/spec diagrams show the relationship between a more general thing and a specific kind of thing. This relationship is described as an “is a” relationship. For example: a car is a vehicle, a truck is a vehicle. Generalization relationship is used to model inheritance. General class is a parent, base, or superclass. Specialized class is a child, derived, or subclass. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Polymorphism Polymorphism or method overriding is when a method is defined in several classes in a gen/spec relationship. The subclass overrides the parent class attributes and/or methods. If a number of classes are involved, the most specific class is used. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Gen/Spec Example Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Finding Classes Classes may be discovered: During interviews or JAD sessions. During brainstorming sessions. By using CRC cards. By examining use cases, looking for nouns. Each noun may lead to a candidate or potential class. Kendall & Kendall © 2005 Pearson Prentice Hall
Determining Class Methods Class methods may be determined by: Using a CRUD matrix. Looking at messages sent between classes. The receiving class must have the message name as a method. Using statechart diagrams. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Statechart Diagrams Statechart diagrams show class states and the events that cause them to transition between states. It is also called a state transition diagram An event happens at a specific time and place. They cause a change of state, or the transition “fires” Kendall & Kendall © 2005 Pearson Prentice Hall
Statechart Diagrams (Continued) Each time an object changes state, some of its attributes must change. There must be a method to change the attributes. Often there is a display screen or Web form to enter the attributes. Kendall & Kendall © 2005 Pearson Prentice Hall
Statechart Diagrams (Continued) Statechart diagrams are not created for all classes. They are created when: A class has a complex life cycle. An instance of a class may update its attributes in a number of ways through the life cycle. A class has an operational life cycle. Two classes depend on each other. The object’s current behavior depends on what happened previously. Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Statechart Example Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Packages Containers for other UML things Show system partitioning Indicate which use cases or classes are grouped into a subsystem Can show component packages Can be physical subsystems Use a folder symbol Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Package Example Kendall & Kendall © 2005 Pearson Prentice Hall
© 2005 Pearson Prentice Hall Steps Used in UML The steps used in UML are: Define the use case model. Continue UML diagramming to model the system. during the systems analysis phase. Develop the class diagrams. Draw statechart diagrams. Begin systems design by refining the UML diagrams. Document your system design in detail. Kendall & Kendall © 2005 Pearson Prentice Hall