Lecture for Chapter 2, Modeling With
Total Page:16
File Type:pdf, Size:1020Kb
09/10/2019 Overview: modeling with UML Modeling with UML What is modeling? What is UML? Use case diagrams Class diagrams Oriented Software Engineering - 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 (James Rumbaugh) the artifacts of a software-intensive system OOSE (Ivar Jacobson) Artifact UML Use case Diagram Booch (Grady Booch) Class Diagram/ Object Diagram Reference: “The Unified Modeling Language User Guide”, Behavioral Diagram : Addison Wesley, 1999. Statechart Diagram Activity Diagram Supported by several CASE tools Interaction Diagram : Sequence Diagram Rational ROSE Collaboration Diagram TogetherJ Implementation Diagram : Component Diagram Deployment 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 actor 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 event 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 <<extends>> Relationship The <<includes>> Relationship <<extends>> relationships represent exceptional or seldom invoked cases. <<includes>> 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. <<includes>> 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 <<includes>> <<includes>> relationship is to the using use case The direction of a <<extends>> (unlike <<extends>> <<extends>> relationship is to the extended use <<includes>> relationships). case <<extends>> <<extends>> CollectMoney <<extends>> <<extends>> OutOfOrder <<extends>> 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