46
Modelling for the faint-hearted Tim Hoverd University of York [email protected]

Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

Modellingfor the faint-hearted

Tim HoverdUniversity of York

[email protected]

Page 2: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Programme

• Modelling

– what, why

• UML

– Objects, classes

• Usage

– Hints and tips

2

Page 3: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Provoked...

3

Element

move( offset : Point )

setLineStyle( style : LineStyle )

setFillPattern( pattern : FillPattern )

Primitive

draw()

undraw()

move( offset : Point )

setLineStyle( style : LineStyle )

setFillPattern( pattern : FillPattern )

Group

move( offset : Point )

setLineStyle( style : LineStyle )

setFillPattern( pattern : FillPattern )

Point

-x : int

-y : int

translate( offset : Point )

Ellipse

-focus : Point

-majorAxis : int

-minorAxis : int

draw()

undraw()

FillPattern

BSpline

draw()

undraw()

LineStyle

Diagram

constituents

*

1

0..1

line style

1

contents

1..*

0..1

selection

0..11

end1

0..1

origin1

0..1

0..1

fill

1

control points

2

0..1

Page 4: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Provoked by...

• appears to be a UML “activity diagram”– extrinsic pathway activity

diagram

• The rounded rectangles should be “actions” or “activities”– Is “factor VII” an activity?

4

Page 5: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

and

• appears to be a UML sequence diagram– “Blood clotting sequence diagram”

• What is “a prothrombin”• What does the message “fibrin

monomers” sent by a prothrombinto a thrombin mean?

• Shouldn’t there be something about the environment here?– Concentrations– Temperature

5

Page 6: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Models

• These diagrams are models– well, they’re parts of a model

• Here’s another one:

– “hybrid-pi” model of a bipolar junction transistor

• A bunch of precisely defined syntax– with precise meaning, even though some of the

symbols represent things that don’t exist (!)

6

Page 7: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

So what?

• We can now design:

– calculate behaviour

– without the massive complexity of doing the quantum mechanics...

• Transistors don’t quite work like that though

– need to use the right model for the situation

7

Page 8: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

More models

• In general, modelling:– takes a real life problem and– represents it in a different language where– that language makes the problem more

amenable to understanding and analysis

• Language:– precise– meaningful– amenable to manipulation– must fit the problem– UML is not always the right answer

8

“In mechanics, it is necessary to take a real life problem and put it in mathematical language.

This process is known as modelling.”

http://www.mathsrevision.net

Page 9: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

But why produce a model?• Why:

– To get something clear in your own head– To communicate with others– To work jointly on some problem– To calculate what will happen in an otherwise intractable circumstance

• For all of these:– clarity of notation and syntax– (you can probably always mess it

up though)

• The best models are the absolutely obvious ones– “Well, that’s obvious. I could have

done that.”

9

Page 10: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Modelling languages• Must be precise, with well understood semantics• Specific purpose• Limitations

– Just because it works in the model doesn’t mean it will for real

• Different languages for apparently similar tasks– Transistor models:

• Small signal, large signal• High speed, low speed• Hybrid-π, h-parameter

– Computer software:• ER models• DFDs• ACP diagrams• UML notations

– there‘s lots of them

10

Page 11: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Explicit and implicit models

• Econometrics models

– Do not necessarily contain lots of little people buying and selling things

– They do not even represent those people explicitly

– Their behaviour is implicit in the model

• War games

– Do not usually contain lots of little soldiers and tanks

– Although they may be explicitly represented

11

Page 12: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Modelling rules

• You need an explicit language– With explicit syntax

• But:1. You must know exactly what you mean by each bit of

syntax2. A reader must know what is meant by each bit of syntax3. Those two semantics must be the same.

• We’re going to look at the UML notations– and how they’re usually used

• You can change the semantics if you want– As is done with the “4+1 model”

12

Page 13: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

UML

• The “Unified Modelling Language”– it’s not a method, or a

“methodology”, or agile, or BDUF, or anything else that’s popular this month

• Essentially a set of notations, for object-orientedsoftware design and implementation

• Grew out of specific design notations, and approaches, of the three amigos– Booch, Rumbaugh, Jacobson– Heavily extended and modified since then– http://www.uml.org for the gory details

• (don’t bother...)

13

Page 14: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

A side-issue

14

Page 15: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Object orientationnot a side-issue

• The UML is explicitly a collectionof notations for OO design

• Over 40 years old, and we’re still confused about it– Simula-67

– Smalltalk-80

• Using UML notations in the “standard” way requires a good knowledge of OO

15

Page 16: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

ObjectOrientation• Simple notion:

– Systems are comprised of collectionsof passive objects• OK, I’m being deliberately extreme...

– Individual objects send messages to each other, in response to messages which the original objects receive

– objects advertise the messages they’re happy to respond to, but hide what they do about it

– (which means that something has to send the first message...)

• If your model needs to be like that, then great– if not, find another notation, or use your own semantics

16

Page 17: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Objects

• Object orientation is about the behaviour of individual objects– “Objects have identity”; they’re not just “stuff”

• An object is asked to do something, by sending it a message• The message receiver follows a pre-defined method of response

to a message• That response may include sending messages to other objects

– that it already knows about

• At its core, OO is about behaviour not structure– the distinction between message and method is core to the

available behaviour

17

Alan KayThe Early History of Smalltalk HOPL, 1993

Page 18: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Objects of a time

• OO appeared in the 60s and 70s• At the time:

– shift to user-centred systems (Sketchpad)– graphical user interfaces (Smalltalk)– move away from stepwise refinement and functional

decomposition– information hiding– mythical man-month– modelling of the real world

• “if I’m building a banking system, let’s explicitly model a bank account”

18

Page 19: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Passive and active objects

• Most objects are passive (usually):– just sit there waiting for a message to arrive

– modelling process is really one of finding the right object to ask to do something for you• hopefully, it will understand

– “I’m sorry, the object Undercarriage does not understand the message lower”...

• Active objects sit there doing stuff...

• Most OO designs are a collection of mostly passive objects

19

Page 20: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

• Modelling in UML provides:– “interaction models”– to describe how objects

interact with each other– objects know about other objects– and the messages they can respond

to

• Describe specificinteractions between a particular set of objects– describes a single scenario– horribly over-specific– but often useful

• Sometimes distinguish active and passive objects

How do objects behave?

20

object

message

method

How do objects get to know about other objects?

A sequence diagram

Page 21: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Ladders and Stairs

21

Page 22: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Because...

• OO is about behaviour

– and delegation to objects that support the desired behaviour

• which they may well do by delegating to another object– which knows a nice object round the corner which...

• Which is a few more stairs...

22

Page 23: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

But what are objects?

• and how do we know what other objects they know?– as that seems kinds of important...

• Instances of classes– Modelling concepts representing a set of similar objects– A class is an abstraction of some behaviour wrapped around

some information– It’s not a functional abstraction

• That behaviour defined by an interface– the alphabet of messages that instances respond to– perhaps as an extension of another class’s interface– patterns of association between its instances

• Objects might well exist in an implementation– classes may well not; they’re pure model

23

Page 24: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

A UML class model

• A fragment of a realistic ATC model• Classes

– the boxes– which have compartments within which are

• the class name (which is a singular noun)• Operations (UML for message) and• Attributes (but they’re boring)

• Associations– the lines

• But what is a class?– It depends...

24

Page 25: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Modelling domains of discourse• Essential models

– classes represent the core concepts of the domain and their inter-relationships

• Specification models– how concepts are required to behave

• Implementation models– how concepts are implemented

• Moving between these domains is not– easy– automatable

• Rich potential for confusion:– User class in an essential model is likely about a person and their

activities– User class in a specification is something that stores a password– User class in an implementation knows about password encryption

25

Page 26: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Associations

• Apparently simple lines between classes

• Give information about theobjects– which are not on this diagram!

• What other objects they know about

• Role names

• Cardinalities– when do they apply?

26

Page 27: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

The objects

• Two flight plan objects• Invisible in class model• Responsibilities appear

– Where these are is a modelling choice that you make– Often hard to work out

• Mysterious unnamed object...

27

Page 28: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

The environment

• The unnamed object issomething outside the system boundary– something in the environment

• The environment, and what it does needs to be modelled• Things to worry about:

– What makes other things happen?• Users, other systems

– What information is in the environment?

28

Page 29: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Generalisation

• Classes may be defined as a specialisation of another

– so, a car is a vehicle

• Substitutability

– “If you ask me for a vehicle and I give you a car, then that’s fine”

– If birds are things that can fly then what are penguins...?

– Or: there must be an association with the generalised concept

29

Vehicle

CarTrain

Road1

vehicles*

Page 30: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Object behaviour

• How to define object behaviour in general?– Sequence diagrams just show one particular scenario

• You could:– Define message signatures and wave your arms lots

• Flight(plan:Flight Plan, aircraft:Aircraft)

– UML Object Constraint Language• class invariants• operation pre- and post-conditions

– Statecharts

– All of the above...

30

Page 31: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Object Constraint Language

• A small example:context Flight

inv: FlightPlan.sectors.includes(current)

• Also pre and post conditions for operations– reminiscent of a formal specification language like Z

and VDM

31

Page 32: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Or just add a comment!

32

Page 33: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

CoordinatingIn sector

Statecharts

• Finite state machines in UML

• Often used to describe states of instances of a class

– edges ≈ messages

– you can use it for what you want

• Lots of UML syntax

33

Page 34: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Activities

• What if you need more than classes, objects, messages, etc.?

– “the controllers do all this complicated stuff and they end up coordinating the flight into the next sector”

• Activity diagrams may be ideal...

34

Page 35: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Inform flight of next sector's frequency

Propose exit flight level

Wave goodbye

Agree entry flight level

Say hello to flight

Next sector controllerCurrent sector controller

current sector : Traversal

next sector : Traversal

Activity diagram

• Extension of statechart notation

• Less software specific than any other part of UML

• Overall view:

– “swimlanes”

– actions, activities, objects

35

Page 36: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Hints and tips for UML modelling

36

• Not a magic solution to all your modelling woes

– it’s just a bunch of syntaxes

– with some patchy tool support

• You could use the notations for whatever you want

– normal use is as a way of constructing OO models

Page 37: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Precise

• Good models are precise

– albeit abstract

• Just because it’s a modeldoesn’t mean that fluffy hand-waving is good

• Every single line, blob, arrow, word should mean something succinct

37

Page 38: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

The system boundaryand the environment

• What are you modelling and what’s outside?– How does what’s outside the boundary affect

what’s inside?

• Should some parts of the environment be modelled?– for example:

• concentrations of some substance

• time of day...

38

Page 39: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Flight

flight level

call sign

clear()

Flight( : Flight Plan, : Aircraft )

Aircraft

tail1

allocation0..1Class modelling

• Are the classes concepts, specifications or implementations?• A class is an intensional description of a set of specific instances

which share the same behaviour– Ask yourself :

• “what would a particular instance be called?”• “what behaviour would it have?”

– That is, what messages could you send it?

• Would a class called “Oxygen” be a good model?– what is “an oxygen”?– what messages can we send to an oxygen?

• Class naming is important– singular noun name– <something> Manager and <something> Handler are not allowed– If you can’t think of a good name it’s a good sign that the model’s

wrong

39

Page 40: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Generalisation

• ...is often a bad idea

• Which is the better model

– why?

40

Automatic gearbox Manual gearbox

Transmission

Car transmission

1

0..1

Automatic carManual car

Car

Page 41: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Generalisation

• ...is often a bad idea

• Which is the better model

– why?

• Because it’s more abstract

41

Automatic carManual car

Car

Transmission

Car transmission

1

0..1

Page 42: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Associations

• Appear on a class diagram– but say what objects are in another object’s

neighbourhood

42

Page 43: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

The relatives

• UML allows lots of different types of association– aggregation– composition– dependency– ternary– navigability– association classes– Occasionally useful but easy to over-use

• Simple rule:– all associations must have a cardinality at each end and– must have at least one role name (“has” is not allowed)

43

Page 44: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

More UML...

• Only mentioned some parts of UML– Deployment diagrams

– Use case models

– Structure diagrams

– Implementation diagrams

– Protocol diagrams

– Ports, links, constraints, etc., etc.

• The important bits have been discussed...

44

Page 45: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

UML tools

• Lots of UML tools around

– Many poor

– Many broken

– Some hilariously expensive

– A couple aren’t bad

– Whiteboards, pens and cameras are excellent

• The diagrams in these slides were done with Magicdraw.

45

Page 46: Modelling for the faint-hearted · •These diagrams are models –well, they’re parts of a model •Here’s another one: –“hybrid-pi” model of a bipolar junction transistor

ICARIS 2009: Modelling for the faint hearted

Conclusion• “Modelling” is a very broad term

– make sure you know what you’re aiming to, for whom, etc.

• UML is just a set of notations that are useful for OO modelling– not necessarily the best choice for all circumstances

• e.g. if you’re just looking at data structures then ER modelling might well be better

– there are very sound reasons for going OO though– but you can always define your own semantics for any

notation (!)

46