620 likes | 633 Views
Why modeling?. A model is a simplification of reality We build models so that we can better understand the system we are developing We build models of complex systems because we cannot comprehend such a system in its entirety. Why Build Models?. To understand the problem better
E N D
Why modeling? • A model is a simplification of reality • We build models so that we can better understand the system we are developing • We build models of complex systems because we cannot comprehend such a system in its entirety
Why Build Models? • To understand the problem better • To communicate with stakeholders • To find errors or omissions • To plan out the design • To generate code
Mental Models Mental models are • assumptions • generalizations • pictures • images that influence how we understand the world and take action
Mental Models • We all have mental models of the world • We all have mental models of the bussinesses which we work at and which we deal with • Mental models also influence our behavior toward the world
Mental Models • Mental Models are often not shared by all stakeholders in the business • This results in dysfunctional and provincial attitudes and behavior • It is essential to develop a shared meta model
UML Model Views • Requirements (use case diagrams) • Static structure (class diagrams) • kinds of objects and their relationships • Dynamic behavior (state machines) • possible life histories of an object • Interactive behavior (activity, sequence, and collaboration diagrams) • flow of control among objects to achieve system-level behavior • Physical implementation structures (component and deployment diagrams) • software modules and deployment on physical nodes
FinancialInstitution client creditor 0..* 0..* owner 0..* Mortgage principal rate term Bank TrustCompany 0..* 1 Class Diagram - Static Structure • Shows the entities in a system and their general relationships association class Person generalization association residence 0..* {ordered} House
RoyalBank : Bank JoeYu:Person first : Mortgage second : Mortgage cottage : House home : House Object Instance Diagram • Shows object instances in a particular case link
InitializeObject Wait forEvent created start/^master.ready() HandleEvent ready stop/ poll/^master.ack() TerminateObject State Machine Diagram • Each state corresponds to a selective receive action state machine initial state state trigger action expression final state transition
poll/defer ready start created created start/^master.ready() ready ready stop/ start/ State Machine Behavior • Event handling details depend on state start/^master.ready()
ActiveObject: Active Objects in the UML • Concurrent incoming events are queued and handled one-at-a-time regardless of priority • run-to-completion (RTC) execution model
Object-Oriented Modeling • Main building block is the object or class • An object is a thing, generally drawn from the vocabulary of the problem space or the solution space • A class is a description of a set of common objects • Every object has identity, state and behavior
Object-Oriented Modeling • The world is made of objects • The system is made of objects • Real world objects communicate with each other • A system is made up of objects communicating with each other
Classes and Objects • Classes, Objects and their relationships are the primary way to model. • A class is like a type and therefore an object is like a variable.
An Object has ... • Attributes (data). • Behaviour (operations). • State (memory) • Identity • Responsibilities
What´s the time? It is 8 p.m. Messages
Time Request Message Time Response Message … Message/Information Flow Messages
What´s the time? It is 8 p.m. Communicating with objects
What´s the time? You will never ask a stop watch for the time, because you know that you do not get an answer. Communicating with objects
An example Object ... • A sensor: • Attributes (data): Value, Rate of change • Behaviour (operations): acquire, report ... • State (memory) Last value, Last Rate • Identity: Robot arm joint sensor • Responsibilities: Gives co-ordinates for arm
The Class: Sensor • All sensors share certain characteristics hence we have a class of sensors. • But each individual example is an object. • (An instance of the class)
Attributes • Describe the state and characteristics of the object. • Must be typed, primitives like integer, real, Boolean, point, area, enumeration. May be language specific. • Visibility may be public (+), private (-) or protected (#).
Attributes (Contd.) • Class variables have scope across every instance of class, change one changes all. • Property strings may be used to define allowable properties of an attribute. Used for enumeration types. • Syntax • visibility name : type-expression = initial-value {property-string} • Only name and type are mandatory.
Attributes hours : Hour minutes : Minute seconds : Second hours : Hour minutes : Minute seconds : Second AMorPM : Boolean
Example Class Name, bold Public, typed Sensor + Linear_Value :Real + Rate_Of_Change : Real = 0.0 + Sensor_Name : String + Sensor_Location: String - Controller: String = “Unspecified” - number_of_sensors: Integer + status: Status = ON{ON, OFF} Default value Private, typed, default value Class variable Property
Operations • Operations describe the „Services“ an object is able perform • An Operation takes some Input • An Operation produces some output Output operation (Input)
Operations • Operations manipulate attributes and perform other tasks. • Scope is the Class. • Operation signature is composed of name, parameters and return type. • name(parameter-list) return-type-expression • Scope and visibility rules apply.
Syntactic Constructs • Formal syntax is as follows • visibility name(parameter-list) return-type-expression {property-string} • parameter-list specified as … • name: type-expression=default-value • All operations must have unique signature. • Default values on parameters are Ok.
Operations getHour getMinutes getSeconds start stop getElapsedTime getHour getMinutes getSeconds getPMorAM getTime
Operations Hour getHour () Minute getMinutes () Second getSeconds () void start () void stop () Time getElapsedTime () Hour getHour () Minute getMinutes () Second getSeconds () Boolean getPMorAM () Time getTime ()
Hour getHour () 8 <- getHour () … Operation Call (not Information Flow) Operation Calls
PMorAMFlag getPMorAM () void start () Time getTime () Time getElapsedTime () Operation Calls
On the Class Diagram Figure Signatures ? Class scope ? Defaults ? -size: Size -pos: Position +figCounter: Integer +draw() +resize(percentX: Integer=25, percentY=30) +returnPos(): Position incCounter(): Integer percentX=10, percentY=10 percentX=27, percentY=30 percentX=25, percentY=30 MyFigure.resize(10,10) MyFigure.resize(27) MyFigure.resize()
Cardinality Examples Employee Dept 1..* Name:String Number:EmpNo Name:Name * Rent 0..1 Member Video Has Customer Account AccNo:Account Balance: Real
Class & Object Representation 0..1 * Rent Member Video Night for day: Video John Doe: Member Sunset Boulevard: Video
Navigable Associations • Used to indicate responsibility, later may be translated into pointer mechanism. • May be bi-directional. owns 0..* Person Car
Recursion • Self referential construct. • Complex construct, may not be supported by target language. * owner User container Directory * * 0..1 authorised user * contents
Qualified Associations • A qualified association relates two Object Classes and a “qualifier”. • One-to-many and many-to-many associations may be qualified. • The qualifier distinguishes among the set of objects at the “many” end of an association.
Qualified Associations * File Directory Is more clearly expressed as ..... File Directory File name
Or-Association • A constraint on two or more associations. • Objects of a class may participate in at most one of the associations at a time. 0..* 1 0..* Insurance Contract Insurance Co {or} 1..* 1..* Person Company
Ordered Association • Shows implicit order of associations. • Default is unordered. {ordered} Screen Window * Visible on {ordered} Sensor Controller * polls
Association Class • Class may be attached to association, and not another class. * employer Company Person 0..1 Employment Association Class Period: dateRange
Shared Aggregation • One person may be a member of many teams. • Person is part of team, shared by N teams. * * Person Team Members
Composition Aggregation • More restrictive. Strong ownership here. • Rules • Parts live inside whole, parts die with whole, like automatic variables. • Multiplicity on whole side must be “0..1”, on part side may be anything. • Composition aggregation forms a tree of parts, shared forms a network of parts.
Three Composition Notations * Text * Listbox Window * Button menu *
Window * • Component not bold. • May use syntax • rollname:classname • Multiplicity shown. Text * Listbox * Button * menu
Generalisation • Generalisation and Inheritance allow sharing of similarities among Classes while also preserving differences. • Inheritance refers to mechanism of sharing attributes & operations between subclasses and their superclass. • Default values of attributes & methods for operations may be overridden in subclass.
Clock StopWatch hours : Hour minutes : Minute seconds : Second AMorPM : Boolean hours : Hour minutes : Minute seconds : Second Hour getHour () Minute getMinutes () Second getSeconds () void start () void stop () Time getElapsedTime () Hour getHour () Minute getMinutes () Second getSeconds () Boolean getPMorAM () Time getTime () Classes
Clock GenericClock hours : Hour minutes : Minute seconds : Second Hour getHour () Minute getMinutes () Second getSeconds () StopWatch AMorPM : Boolean void start () void stop () Time getElapsedTime () Boolean getPMorAM () Time getTime () Inheritance
Example General Financial service Specific Pension Mortgage Personal Loan Insurance