Overview UML Unified Modeling Language What is Modeling? What is UML? A brief history of UML Understanding the basics of UML UML diagrams UML Modeling tools 2 Modeling Object Oriented Modeling Describing a system at a high level of Abstraction A model of the system Used for requirements and specification Is it necessary to model software systems? Many notations over time State machines Entity-relationship diagrams Dataflow diagrams 3 4 What is UML? UML stands for Unified Modeling Language It is a industry-standard graphical language for specifying, visualizing, constructing, and documenting the artifacts of software systems The UML uses mostly graphical notations to express the OO analysis and design of software projects Simplifies the complex process of software design 5 Why we use UML for Modeling? Use graphical notation to communicate more clearly than natural language (imprecise) and code (too detailed) Help acquire an overall view of a system UML is not dependent on any one language or technology UML moves us from fragmentation to standardization 6 1
History of UML Recent History: 1980 s The rise of object-oriented programming New class of OO modeling languages By early 90 s, over 50 OO modeling languages 7 8 Recent History: 1990 s Three leading OO notations decide to combine Grady Booch (BOOCH) James Rumbaugh (OML: Object Modeling Technique) Ivar Jacobsen (OOSE: OO Soft. Eng) Why? Natural evolution towards each other Effort to set an industry standard 9 UML UML stands for Unified Modeling Language Design by committee Many interest groups participating Everyone wants their favorite approach to be in 10 UML Resulting design is huge Many features Many loosely unrelated styles under one roof Could also be called Union of all Modeling Languages This Lecture We discuss Use Case Diagrams Class Diagrams Sequence Diagrams Activity Diagrams State Diagrams This is a subset of UML But probably the most used subset 11 12 2
Overview of UML Diagrams Structural : element of spec. irrespective of time Class Component Deployment Object Composite structure Package Profile Behavioral : behavioral features of a system / business process Activity State machine Use case Interaction Interaction : emphasize object interaction Communication(collaberati on) Sequence Interaction overview Timing Use-Cases Describe functionality from the user s perspective One (or more) use-cases per kind of user May be many kinds in a complex system Use-cases capture requirements 13 14 An Example Use-Case in UML An Example Use-Case in UML Name Normal Train Ride Actors Passenger Entry Condition Passenger at station Exit Condition Passenger leaves station Event-flow Passenger presses request button Train arrives and stops at platform Doors open Passenger steps into train Doors close Passenger presses request button for final stop Doors open at final stop Passenger exits train Non-functional requirements 15 16 Use Case Diagram Class Diagrams Graph showing Actors Use cases Edges actor-case if that actor is involved in that case Actors Stick figures Use cases Ovals Describes the structure of a system by showing the system s classes, their attributes, operations (or methods), and the relationships among the classes Used for requirement capture, end-user interaction Detailed class diagrams are used for developers 17 18 3
Class Representation An example of a Class Each class is represented by a rectangle subdivided into three compartments Name Attributes Operations Modifiers are used to indicate visibility of attributes and operations. + is used to denote Public visibility (everyone) # is used to denote Protected visibility (friends and derived) - is used to denote Private visibility (no one) By default, attributes are hidden and operations are visible. Describe classes In the OO sense Each box is a class List attributes List operations The more detail, the more like a design it becomes Account_Name - Customer_Name - Balance +addfunds( ) +withdraw( ) +transfer( ) Name Attributes Operations 19 20 Class Diagrams: OO Relationships OO Relationships: Generalization Many different kinds of edges to show different relationships between classes Generalization (parent-child relationship) Association (student enrolls in course) Associations can be further classified as Aggregation Composition Subtype1 Supertype Subtype2 Generalization express a parent-child relationship (inheritance) among related classes Used for abstracting details in several layers Denoted by open triangle 21 22 Generalization Example OO Relationships: Associations 23 Represent relationship between instances of classes Student enrolls in a course Courses have students Courses have exams Etc. Association has two ends Role names (e.g. enrolls) Multiplicity (e.g. One course can have many students) Navigability (unidirectional, bidirectional) 24 4
Associations: Multiplicity and Roles University Symbol Meaning 1 Multiplicity 1 One and only one 0..1 Zero or one M..N 0..1 employer From M to N (natural language) * From zero to any positive integer 0..* From zero to any positive integer 1..* From one to any positive integer student * * teacher Person Role A given university groups many people; some act as students, others as teachers. A given student belongs to a single university; a given teacher may or may not be working for the university at a particular time. 25 OO Relationships: Aggregation AGGREGATION Example Container Class Class C Class E 1 Class E 2 Apples Containee Classes Bag Milk [From Dr.David A. Workman] Aggregation: is a variant of the has a or association relationship; aggregation is more specific than association. It is an association that represents a part-whole or part-of relationship. It is a specific kind of Container- Containee relationship. Aggregation can occur when a class is a collection or container of other classes, but where the contained classes do not have a strong life cycle dependency on the container essentially, if the container is destroyed, its contents are not. 26 OO Relationships: Composition Whole Class Class W Class P 1 Class P 2 Example Engine Part Classes Automobile Transmission Composition: is a stronger variant of the owns a or association relationship; composition is more specific than aggregation. It is a specific kind of Whole-Part relationship. Composition usually has a strong life cycle dependency between instances of the container class and instances of the contained class(es): If the container is destroyed, normally every instance that it contains is destroyed as well. It expresses a relationship where an instance of the Whole-class has the responsibility to create and initialize instances of each Part-class. Composition should also be used to express relationship where instances of the Whole-class have exclusive access to and control of instances of the Part-classes. Composition should be used to express a relationship where the behavior of Part instances is undefined without being related to an instance of the Whole. And, conversely, the behavior of the Whole is ill-defined or incomplete if one or more of the Part instances are undefined. Sequence Diagrams Sequence diagrams Refine use cases Gives view of dynamic behavior of classes A sequence diagram shows object interactions arranged in time sequence. It depicts the objects and classes involved in the scenario and the sequence of messages exchanged between the objects needed to carry out the functionality of the scenario. [From Dr.David A. Workman] 27 28 Sequence Diagrams Example Sequence Diagram A table Columns are classes or actors Rows are time steps Entries show control/data flow Method invocations Important changes in state Classes & Actors 29 30 5
Example Sequence Diagram Example Sequence Diagram Method invocation Note: These are all synchronous method calls. There are other kinds of invocations. Invocation lifetime spans lifetimes of all nested invocations 31 32 Example Sequence Diagram Example Sequence Diagram: Make a phone call Caller Phone Recipient Picks up Lifelines fill in time between invocation s Dial tone Dial Ring notification Ring Picks up Hello 33 34 Sequence Diagram: Object interaction Activity Diagrams Self-Call: A message that an Object sends to itself. A Synchronous B Reincarnation of flow charts Uses flowchart symbols Condition: indicates when a message is sent. The message is sent only if the condition is true. Asynchronous Transmission delayed Emphasis on control-flow Condition Iteration [condition] remove() *[for each] remove() Two useful flowchart extensions Hierarchy A node may be an activity diagram Self-Call Swim lanes 35 36 6
Example Activity Diagram Example Activity Diagram 37 38 Example Activity Diagram Another Example Activity Diagram 39 40 StateCharts State Diagrams (Traffic light example) Hierarchical finite automata Invented by David Harel, 1983 Transition State Traffic Light Red Start Specify automata with many states compactly Yellow Complications in meaning of transitions What it means to enter/exit a compound state Event Green 41 42 7
Example Simple StateChart StateChart for Buttons + Train 43 44 Opinions about UML: What s Good Opinions On UML: What s Bad A common language Makes it easier to share requirements, specs, designs Hodge-podge of ideas Union of most popular modeling languages Sublanguages remain largely unintegrated Visual syntax is useful, to a point A picture is worth 1000 words For the non-technical, easier to grasp simple diagrams than simple pseudo-code To the extent UML is precise, forces clarity Much better than natural language Commercial tool support Something natural language could never have 45 Visual syntax does not scale well Many details are hard to depict visually Ad hoc text attached to diagrams No visualization advantage for large diagrams 1000 pictures are very hard to understand Semantics is not completely clear Some parts of UML underspecified, inconsistent Plans to fix 46 UML is Happening What UML Modeling tools we use today? UML is being widely adopted By users By tool vendors By programmers A step forward Seems useful First standard for high-levels of software process Expect further evolution, development of UML List of UML tools http://en.wikipedia.org/wiki/list_of_uml_tools ArgoUML: http://argouml.tigris.org/ Rational Rose (www.rational.com) by IBM UML Studio 7.1 ( http://www.pragsoft.com/) by Pragsoft Corporation: Capable of handling very large models (tens of thousands of classes). Educational License US$ 125.00; Freeware version. TogetherSoft Control Center; TogetherSoft Solo ( http://www.borland.com/together/index.html) by Borland 47 48 8