09/10/2019

Overview: modeling with UML Modeling with UML  What is modeling?  What is UML?  diagrams

 Class diagrams

Oriented SoftwareEngineering

- Object

What is modeling? Example: street map

 Modeling consists of building an abstraction of reality.  Abstractions are simplifications because:  They ignore irrelevant details and  They only represent the relevant details.  What is relevant or irrelevant depends on the purpose of the model.

Why model software? Systems, Models and Views

Why model software?  A model is an abstraction describing a subset of a system  A view depicts selected aspects of a model  Software is getting increasingly more complex  A notation is a set of graphical or textual rules for depicting views  Windows XP > 40 million lines of code  Views and models of a single system may overlap each other  A single programmer cannot manage this amount of code in its entirety.  Code is not easily understandable by developers who did not Examples: write it  System: Aircraft  We need simpler representations for complex systems  Models: Flight simulator, scale model  Modeling is a mean for dealing with complexity  Views: All blueprints, electrical wiring, fuel system

1 09/10/2019

Systems, Models and Views Models, Views and Systems (UML)

Flightsimulator Blueprints * * System Model View Aircraft Described by Depicted by Model 2 View 2 View 1 System Airplane: System View 3 Model 1 Scale Model: Model Flight Simulator: Model Electrical Wiring Scale Model Blueprints: View Fuel System: View Electrical Wiring: View

What is UML? What is UML?

 UML (Unified Modeling Language)  The Unified Modeling Language (UML) is a language for  Specifying  An emerging standard for modeling object-oriented software.  Visualizing  Resulted from the convergence of notations from three leading  Constructing object-oriented methods:  Documenting

 OMT () the artifacts of a software-intensive system   OOSE () Artifact UML  Use case Diagram  Booch ()  /  Reference: “The Unified Modeling Language User Guide”,  Behavioral Diagram : Addison Wesley, 1999.  Statechart Diagram   Supported by several CASE tools  Interaction Diagram :   Rational ROSE  Collaboration Diagram  TogetherJ  Implementation Diagram : 

UML History UML

 Use case Diagrams  Describe the functional behavior of the system as seen by the user.  Class diagrams  Describe the static structure of the system: Objects, Attributes, Associations  Sequence diagrams  Describe the dynamic behavior between actors and the system and between objects of the system  Statechart diagrams  Describe the dynamic behavior of an individual object (essentially a finite state automaton)  Activity Diagrams  Model the dynamic behavior of a system, in particular the workflow (essentially a flowchart)

2 09/10/2019

UML : Use case diagrams UML : Class diagrams Class diagrams represent the structure of the system Package Use case Watch Association Class Actor Multiplicity Watch ReadTime 1 1 1 1 2 1 2 1 PushButton LCDDisplay Battery Time SetTime state blinkIdx load now WatchUser WatchRepairPerson push() blinkSeconds() release() blinkMinutes() blinkHours() stopBlinking() ChangeBattery referesh()

Attribute Use case diagrams represent the functionality of the system Operations from user’s point of view

UML : Statechart diagrams for objects with UML : Sequence diagram interesting dynamic behavior Actor Event State Object Initial state [button1&2Pressed][button2Pressed] :Watch :LCDDisplay :Time :WatchUser BlinkHours IncrementHrs

pressButton1() blinkHours() [button1Pressed] pressButton1() blinkMinutes() Transition

Message pressButton2() [button1&2Pressed][button2Pressed] incrementMinutes() BlinkMinutes IncrementMin. refresh() pressButtons1And2() commitNewTime() [button1Pressed] stopBlinking() [button1&2Pressed][button2Pressed] BlinkSeconds IncrementSec. Activation Lifeline

StopBlinkingFinal state Sequence diagrams represent the behavior as interactions Represent behavior as states and transitions

Other UML Notations UML Core Conventions

UML provide other notations that we will be introduced in  Rectangles are classes or instances subsequent lectures, as needed.  Ovals are functions or use cases  Instances are denoted with an underlined names  Implementation diagrams  myWatch:SimpleWatch  Component diagrams  Joe:Firefighter  Deployment diagrams  Types are denoted with non underlined names  Introduced in lecture on System Design  SimpleWatch  Object constraint language  Firefighter  Introduced in lecture on Object Design  Diagrams are graphs  Nodes are entities  Arcs are relationships between entities

3 09/10/2019

Use Case Diagrams Actors

 Used during requirements  An models an external entity which elicitation to represent external communicates with the system: behavior  User  External system  Actors represent roles, that is, a type of user of the system  Physical environment Passenger  Use cases represent a sequence of  An actor has a unique name and an optional interaction for a type of Passenger description. functionality  Examples:  The use case model is the set of all use cases. It is a complete  Passenger: A person in the train description of the functionality of  GPS satellite: Provides the system with GPS PurchaseTicket the system and its environment coordinates

Use Case Use Case Diagram: Example

A use case represents a class of Name: Purchase ticket Event flow: functionality provided by the system as 1. Passenger selects the number of an flow. Participating actor: Passenger zones to be traveled. 2. Distributor displays the amount due. Entry condition: A use case consists of: 3. Passenger inserts money, of at  Passenger standing in front of least the amount due. PurchaseTicket  Unique name ticket distributor. 4. Distributor returns change.  Participating actors  Passenger has sufficient money to purchase ticket. 5. Distributor issues ticket.  Entry conditions  Flow of events Exit condition: Anything missing?  Exit conditions  Passenger has ticket.  Special requirements Exceptional cases!

The <> Relationship The <> Relationship

 <> relationships represent exceptional or seldom invoked cases.  <> relationship represents behavior that is factored  The exceptional event flows are out of the use case. Passenger factored out of the main event flow Passenger for clarity.  <> behavior is factored out for reuse, not because  Use cases representing exceptional PurchaseMultiCard it is an exception. flows can extend more than one PurchaseTicket use case. PurchaseSingleTicket  The direction of a <> <> relationship is to the using use case  The direction of a <> (unlike <> <> relationship is to the extended use <> relationships). case <> <> CollectMoney <> <> OutOfOrder <> TimeOut

NoChange Cancel Cancel NoChange

4 09/10/2019

Use Case Diagrams: Summary Class Diagrams

 Use case diagrams represent external behavior  Use case diagrams are useful as an index into the use cases TarifSchedule Trip  Use case descriptions provide meat of model, not the use case zone:Zone Enumeration getZones() * diagrams. Price getPrice(Zone) * Price: Price  All use cases need to be described for the model to be useful.

 Class diagrams represent the structure of the system.  Used  during requirements analysis to model problem domain concepts  during system design to model subsystems and interfaces  during object design to model classes.

Classes Instances

TarifSchedule Table zone2price Enumeration getZones() tarif_1974:TarifSchedule Name Price getPrice(Zone) zone2price = { {‘1’, .20}, TarifSchedule {‘2’, .40}, zone2price Attributes Signature {‘3’, .60}} getZones() getPrice() Operations TarifSchedule  An instance represents a phenomenon.  The name of an instance is underlined and can contain the class of the  A class represent a concept instance.  A class encapsulates state (attributes) and behavior (operations).  The attributes are represented with their values.  Each attribute has a type.  Each operation has a signature.  The class name is the only mandatory information.

Actor vs Instances Associations

 What is the difference between an actor , a class and an instance?  Actor: TarifSchedule TripLeg  An entity outside the system to be modeled, interacting with the Price Enumeration getZones() * system (“Passenger”) Price getPrice(Zone) * Zone  Class:  An abstraction modeling an entity in the problem domain, must be modeled inside the system (“User”)  Associations denote relationships between classes.  Object:  The multiplicity of an association end denotes how many objects the source  A specific instance of a class (“Joe, the passenger who is purchasing object can legitimately reference. a ticket from the ticket distributor”).

5 09/10/2019

1-to-1 and 1-to-many Associations Many-to-Many Associations

Country Has-capital City * name:String name:String Lists StockExchange * * Company One-to-one association tickerSymbol Point Polygon * x: Integer Lists * 1 Company y: Integer StockExchange draw() tickerSymbol SX_ID

One-to-many association

From Problem Statement To Object Model From Problem Statement to Code

Problem Statement : A stock exchange lists many companies. Each company is identified by a ticker Symbol Problem Statement: A stock exchange lists many companies. Each Class Diagram: company is uniquely identified by a ticker symbol StockExchange * * Company Lists tickerSymbol Class Diagram: Java Code public class StockExchange { * * Company private Vector m_Company = new Vector(); StockExchange }; Lists tickerSymbol public class Company { public int m_tickerSymbol; private Vector m_StockExchange = new Vector(); };

Aggregation Qualifiers

 An aggregation is a special case of association denoting a “consists of” hierarchy. Without qualification 1 * File  The aggregate is the parent class, the components are the children class. Directory filename Exhaust system Exhaust system With qualification 1 0…1 1 0..2 1 0..2 Directory filename File

Muffler Tailpipe Muffler Tailpipe diameter diameter diameter diameter   A solid diamond denotes composition, a strong form of aggregation where Qualifiers can be used to reduce the multiplicity of an components cannot exist without the aggregate. (Bill of Material) association. TicketMachine

3 ZoneButton

6 09/10/2019

Inheritance Object Modeling in Practice: Class Identification

Foo Button Betrag CustomerId

Deposit() CancelButton ZoneButton Withdraw() GetBalance()

 The children classes inherit the attributes and operations of the parent class.  Inheritance simplifies the model by eliminating redundancy. Class Identification: Name of Class, Attributes and Methods

Object Modeling in Practice: Object Modeling in Practice ctd Encourage Brainstorming

Account “Dada” Foo Betrag Betrag Betrag Customer Bank CustomerIdAccountId CustomerId CustomerId Name Name Deposit() CustomerId Deposit() Deposit() Withdraw() Withdraw() Withdraw() GetBalance() GetBalance() GetBalance() Account

Betrag CustomerId 1) Find New Objects Deposit() 2) Iterate on Names, Attributes and Methods Naming is important! Withdraw() Is Foo the right name? GetBalance()

Object Modeling in Practice: A Banking System Practice Object Modeling: Iterate, Categorize!

Account Account Bank Customer Amount * * Has Betrag Name AccountId Name Customer CustomerIdAccountI AccountId * Bank CustomerIdAccountI Has d Name Deposit() d Withdraw() Name Deposit() CustomerId CustomerId() Withdraw() GetBalance() GetBalance()

1) Find New Objects Savings Checking Mortgage Account Account Account 2) Iterate on Names, Attributes and Methods 3) Find Associations between Objects 4) Label the assocations Withdraw() Withdraw() Withdraw() 5) Determine the multiplicity of the assocations

7 09/10/2019

Packages UML sequence diagrams

 A is a UML mechanism for organizing elements into groups (usually not an application domain concept)  Used during requirements analysis TicketMachine  To refine use case descriptions  Packages are the basic grouping construct with which you may Passenger organize UML models to increase their readability.  to find additional objects selectZone() (“participating objects”)  Used during system design  to refine subsystem interfaces DispatcherInterface insertCoins()  Classes are represented by columns  Messages are represented by Notification IncidentManagement arrows pickupChange()  Activations are represented by  A complex system can be decomposed into subsystems, where narrow rectangles each subsystem is modeled as a package  Lifelines are represented by pickUpTicket() dashed lines

Nested messages Iteration & condition

…continued from previous slide...

ZoneButton TarifSchedule Display ChangeProcessor CoinIdentifier Display CoinDrop Passenger Passenger insertChange(coin) selectZone() * lookupCoin(coin) lookupPrice(selection) price price Iteration displayPrice(owedAmount) displayPrice(price) Dataflow [owedAmount<0] returnChange(-owedAmount) …to be continued... Condition

 The source of an arrow indicates the activation which sent the message …to be continued...  An activation is as long as all nested activations  Iteration is denoted by a * preceding the message name  Horizontal dashed arrows indicate data flow  Condition is denoted by boolean expression in [ ] before the message  Vertical dashed lines indicate lifelines name

Creation and destruction Sequence Diagram Summary

…continued from previous slide...  UML sequence diagram represent behavior in terms of

ChangeProcessor interactions. Passenger Creation  Useful to find missing objects. createTicket(selection)  Time consuming to build but worth the investment. Ticket print()  Complement the class diagrams (which represent structure).

free() Destruction

 Creation is denoted by a message arrow pointing to the object.  Destruction is denoted by an X mark at the end of the destruction activation.  In garbage collection environments, destruction can be used to denote the end of the useful life of an object.

8 09/10/2019

State Chart Diagrams Activity Diagrams

Event Initial state State  An diagram shows flow control within a system [button1&2Pressed][button2Pressed] BlinkHours IncrementHrs Handle Document Archive Incident Incident Incident Transition [button1Pressed]  An activity diagram is a special case of a state chart diagram in [button1&2Pressed][button2Pressed] which states are activities (“functions”) BlinkMinutes IncrementMin.  Two types of states:  Action state: [button1Pressed]  Cannot be decomposed any further [button1&2Pressed][button2Pressed]  Happens “instantaneously” with respect to the level of abstraction used in the model BlinkSeconds IncrementSec.  Activity state:  Can be decomposed further Final state StopBlinking  The activity is modeled by another activity diagram Represent behavior as states and transitions

Statechart Diagram vs. Activity Diagram Activity Diagram: Modeling Decisions

Statechart Diagram for Incident (similar to Mealy Automaton) (State: Attribute or Collection of Attributes of object of type Incident) Event causes [lowPriority] Open Allocate State transition Incident Resources

Active Inactive Closed Archived [fire & highPriority] Incident- Incident- Incident- Documented Handled Archived [not fire & highPriority] Notify Activity Diagram for Incident (similar to Moore Fire Chief (State: Operation or Collection of Operations) Notify Police Chief

Triggerless Completion of activity Transition causes state transition

Activity Diagrams: Modeling Concurrency Activity Diagrams: Swimlanes

 Synchronization of multiple activities  Actions may be grouped into swimlanes to denote the object or subsystem that implements the actions.  Splitting the flow of control into multiple threads

Allocate Dispatcher Allocate Resources Splitting Resources Synchronization

Open Coordinate Archive Open Coordinate Archive Incident Resources Incident Incident Resources Incident FieldOfficer Document Document Incident Incident

9 09/10/2019

UML Summary

 UML provides a wide variety of notations for representing many aspects of software development  Functional model: Use case diagram  Object model: class diagram  Dynamic model: sequence diagrams, statechart and activity diagrams

10