Um Land Classes

download Um Land Classes

of 73

Transcript of Um Land Classes

  • 7/31/2019 Um Land Classes

    1/73

  • 7/31/2019 Um Land Classes

    2/73

  • 7/31/2019 Um Land Classes

    3/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    In 1994, more than 50 OO methods!

    3

    UML is ... unified

    Meyer

    Before and afterconditions

    Harel

    StatechartsGamma, et al

    Frameworks and patterns,

    HP Fusion

    Operation descriptions andmessage numbering

    Embley

    Singleton classes andhigh-level view

    Wirfs-Brock

    Responsibilities

    Odell

    Classification

    Shlaer - Mellor

    Object lifecycles

    Rumbaugh

    OMT

    Booch

    Booch method

    Jacobson

    OOSE

  • 7/31/2019 Um Land Classes

    4/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 4

    Designed by Booch, Rumbaugh, Jacobson (3 amigos)

    Started in 1994; version 1.0 finished in 1997

    Version 1.5 (1.4.2) since July 2004: current

    Version 2.0 in beta since 2004 - final late 2005

    To end the OO method wars: standard

    Standard adopted by OMG (also known from Corba)

    UML History

  • 7/31/2019 Um Land Classes

    5/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 5

    General Goals of UML

    Model systems using OO concepts

    Establish an explicit coupling to conceptual as well asexecutable artifacts

    To create a modeling language usable by both humansand machines

    Models different types of systems (informationsystems, technical systems, embedded systems, real-time systems, distributed systems, system software,business systems, UML itself, ...)

  • 7/31/2019 Um Land Classes

    6/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    UML Worldview

    Two concepts:

    Views

    Diagrams

    6

  • 7/31/2019 Um Land Classes

    7/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 7

    UML Views

    Each view is a projection of the complete system.

    Each view highlights particular aspects of the system.

    Views are described by a number of diagrams.

    No strict separation, so a diagram can be part ofmore than one view.

  • 7/31/2019 Um Land Classes

    8/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 8

    UML Views

    Use CaseView

    DeploymentView

    ConcurrencyView

    ComponentView

    LogicalView

  • 7/31/2019 Um Land Classes

    9/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 9

    Use-Case diagram (see later)

    Class diagram (see later)

    Object diagram

    State diagramSequence diagram

    Collaboration diagram

    Activity diagram

    Component diagram

    Deployment diagram

    UML Diagrams...

  • 7/31/2019 Um Land Classes

    10/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 10

    State Diagram

    Represent the behaviour of a class in terms of(evolution of) its state.

  • 7/31/2019 Um Land Classes

    11/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 11

    Sequence Diagram

    Temporal representation of objects and theirinteractions.

  • 7/31/2019 Um Land Classes

    12/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 12

    Collaboration Diagram

    Spatial representation of objects, relations andinteractions.

  • 7/31/2019 Um Land Classes

    13/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 13

    Object Diagram

    Represents objects and their relations; corresponds tosimplified collaboration diagrams (no message sends).

  • 7/31/2019 Um Land Classes

    14/73Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 14

    Activity Diagram

    Represent the behaviour of one operation in terms ofactions.

  • 7/31/2019 Um Land Classes

    15/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 15

    Component Diagram

    Represent the physical components of a system.

  • 7/31/2019 Um Land Classes

    16/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 16

    Deployment Diagram

    Represent the deployment of a system on hardware.

  • 7/31/2019 Um Land Classes

    17/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    UML Metamodel

    Some mental exercise:

    Semantic of UML diagrams is described in UML!

    Each diagram is an instance of a UML meta model

    In other words: each diagram shows a simplified view ofthe meta model

    UML Meta Model describes all possibilities

    17

  • 7/31/2019 Um Land Classes

    18/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Common UML: Elements

    Core : Element

    used for both model elements as visual elements

    model element: represents system abstraction whilemodelling

    visual element: textual or graphical representation of amodel element that allows a user to interact

    18

  • 7/31/2019 Um Land Classes

    19/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Meta-model part: Element

    19

    Packet

    Element

    Model

    Element

    Visual

    Element

    Model

    references0..*

    0..*

    contains

    0..*

    0..1

    1 0..1

    0..*1..*

    projects

  • 7/31/2019 Um Land Classes

    20/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Common UML: mechanisms

    Across UML, a number of common mechanisms areused:

    Stereotypes

    Tagged Values Notes

    Constraints

    Dependency relationships

    (type, instance) and (type, class) dichotomies

    20

  • 7/31/2019 Um Land Classes

    21/73

  • 7/31/2019 Um Land Classes

    22/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/200622

    Stereotypes

    Allows to define a new kind of model element basedon an existing one

    Basically adds extra semantics There are predefined stereotypes

    Stereotypes

    Stereotype name Stereotype icon

  • 7/31/2019 Um Land Classes

    23/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/200623

    Tagged Values

    Tagged values

    Name-value pairs of information

    (name, value)

    Hold additional information about elements

  • 7/31/2019 Um Land Classes

    24/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Notes

    Comment attached to one or more elements

    Holds no semantic information, just information

    use stereotypes for semantic information

    Graphically:

    24

    Note

  • 7/31/2019 Um Land Classes

    25/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/200625

    Constraints

    Restrictions that limit the usage of an element or thesemantics of an element

    No syntax specified

    Can be natural text, pseudo-code, mathematicalexpressions, OCL (object constraint language), ...

  • 7/31/2019 Um Land Classes

    26/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Dependency Relationships

    One-directional usage relationship between twomodel elements (called source and target)

    Notes or constraints are valid sources fordependency relationships

    Graphical notation:

    (client depends on provider)

    26

    Client Provider

  • 7/31/2019 Um Land Classes

    27/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Common UML: Primitive Types

    Primitive types:

    Boolean: enumerated type {true, false}

    Expression: string with some semantics

    List: ordered sequence, possible indexed

    Multiplicity: see next

    Name: string used to indicate element

    Point: tuple (x,y,z) that indicates point in space

    String: list of characters designated with a name

    Time: represents absolute or relative time

    Non-interpreted: blob

    27

  • 7/31/2019 Um Land Classes

    28/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Primitive type: multiplicity

    Non-empty set of positive integers

    Syntax:

    multiplicity ::= [interval | number] { , multiplicity}

    interval ::= number .. numbernumber ::= positive_number | name | *

    Examples:

    1

    1, 3..4, 5..8

    0..*

    28

  • 7/31/2019 Um Land Classes

    29/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Common UML : Packet

    Groups model elements

    All elements belong to a package

    There is a root package for the system

    Can contain other packets, since packets are modelelements themselves

    Enforces namespace

    Two elements in a different package can have the samename

    29

  • 7/31/2019 Um Land Classes

    30/73

  • 7/31/2019 Um Land Classes

    31/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Package import

    Elements can be shared between packages

    The import relation between packages is modelledusing a dependency relationship stereotyped with import

    31

    Client

    Provider

  • 7/31/2019 Um Land Classes

    32/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Package visibility

    Elements contained in a package are not visible to theoutside world

    except when they are declared public(usingstereotypes, for example)

    otherwise they are implementation (not visible)

    32

    Cl D

  • 7/31/2019 Um Land Classes

    33/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 33

    Class Diagrams

    Static model type

    A view of the system in terms of classes andrelationships

    Classes not only describe attributes but alsobehaviour !

    Description of object types .

    Attributes and behaviour of a type of objects All objects are instances of a certain class

    A Cl UML

  • 7/31/2019 Um Land Classes

    34/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 34

    A rectangle divided into 3 compartments :

    name, attributes, operations

    A Class in UML

    Name

    attributes

    operations

    Uppercase, bold

    lowercase+, -, # for visibility= for defaults

    { } for enumerationsunderline : static

    S l

  • 7/31/2019 Um Land Classes

    35/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 35

    Some examples

    Invoice

    + amount : Real+ date : Date = Current date+ customer : String- administrator : String = "Unspecified"- number of invoices : Integer+ status : Status = unpaid {unpaid, paid}

    Figure

    # size : Size

    # pos : Position

    + draw()

    + scaleFigure(percent : Integer = 25)

    + returnPos() : Position

    R l i hi B Cl

  • 7/31/2019 Um Land Classes

    36/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 36

    Relationships Between Classes

    An association is a connection between classes

    usage

    Ageneralization is a relationship between a moregeneral and a more specific element

    inheritance

    A refinement is a relationship between twodescriptions of the same thing but at different levels ofabstraction

    A realization is a relationship between elements whereone carries out what the other specifies

  • 7/31/2019 Um Land Classes

    37/73

    A i i R l i hi

  • 7/31/2019 Um Land Classes

    38/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 38

    Association Relationship

    Drawn as line between classes

    By default bidirectional

    but particular direction can be indicated

    Can contain multiplicities

    a range that tells us how many objects are linked

    9 examples to show different aspects and give some

    additional information...

    E l 1

  • 7/31/2019 Um Land Classes

    39/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 39

    Example 1

    Model the following:

    An author can use a computer.

    E l 1 S l i

  • 7/31/2019 Um Land Classes

    40/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 40

    Example 1 Solution

    association

    associationname

    associationdirection

    Author Computeruses

    O i i di i

  • 7/31/2019 Um Land Classes

    41/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    On association directions...

    41

    Author Computeruses

    Author Computeruses

    Author Computeruses

    Author Computeruses >

    E l 2

  • 7/31/2019 Um Land Classes

    42/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 42

    Example 2

    Model the following:

    A user can own 0 or more cars. Each car is owned by1 or more persons

    S l ti E l 2

  • 7/31/2019 Um Land Classes

    43/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 43

    Solution Example 2

    Multiplicities

    A Person Owns 0 or many CarsA Car is Owned by 1 or many Persons

    Person CarOwns

    Owned By0..*

    1..*

    C M lti li iti

  • 7/31/2019 Um Land Classes

    44/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 44

    Common Multiplicities

    (See primitive types for all possibilities)

    Multiplicity Notation

    optional 0..1

    zero or more 0..* or *

    at least one 1..*

    exactly one 1 or left blank

    E l 3

  • 7/31/2019 Um Land Classes

    45/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 45

    Example 3

    Model the following:

    Nodes can be connected to other nodes.

    R i A i ti

  • 7/31/2019 Um Land Classes

    46/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 46

    Recursive association: connecting a class to itself

    Recursive Associations

    Node

    Connects

    *

    *

    Example 4

  • 7/31/2019 Um Land Classes

    47/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 47

    Example 4

    Model the following:

    A Canvas contains many Figures which are identifiedby an identifier

  • 7/31/2019 Um Land Classes

    48/73

    Qualified associations as restrictions

  • 7/31/2019 Um Land Classes

    49/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Qualified associations as restrictions

    Qualified association subdivides the referenced set of

    objects into partitions where, viewed from the initialobject, each partition may occur only once

    Example: employees are partitioned: all employees

    with the same initials belong to one partition

    49

    Company

    nameaddress

    Employee

    nameemploys >

    *1initials

    company initials employee

    ULB RW Roel Wuyts

    ULB TM Thierry Massart

    UMH TM Tom Mens

    Example 5

  • 7/31/2019 Um Land Classes

    50/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 50

    Example 5

    Model the following:

    An insurance company has insurance contracts, whichrefer to one or more customers.

    A customer has insurance contracts (zero or more),

    which refer to one insurance company. An insurance contract is between an insurance company

    and one or more customers. The insurance contractrefers to both a customer (or customers) and an

    insurance company. The insurance contract is expressed in an (zero or one)

    insurance policy (a written contract of insurance). Theinsurance policy refers to the insurance contract.

  • 7/31/2019 Um Land Classes

    51/73

    Example 6

  • 7/31/2019 Um Land Classes

    52/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 52

    Example 6

    Model the following:

    An insurance contract belongs to a customer or to acompany. A customer can have multiple insurances. Aninsurance contract has an ordered collection of 1 or

    more customers.

    Example 6:or associations

  • 7/31/2019 Um Land Classes

    53/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 53

    Put constraint between the associations

    Example 6: or associations

    constraints

    Insurance

    Company

    Insurance

    Contract

    *

    1..*

    hasrefers to

    Customer

    1..*has

    refers to

    { or }

    { ordered }

  • 7/31/2019 Um Land Classes

    54/73

    Example 7

  • 7/31/2019 Um Land Classes

    55/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 55

    Example 7

    Model the following:

    An elevator control manipulates four elevators. Oneach link between the elevators and the elevatorconrol, there is a queue. Each queue stores the

    requests from both the elevator control and theelevator itself. When the elevator control chooses anelevator to perform a request from a passengeroutside the elevator, the elevator control reads each

    queue and choses the elevator that has the shortestqueue. The choice could also be made using someclever algorithm.

    Example 8: association classes

  • 7/31/2019 Um Land Classes

    56/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 56

    Example 8: association classes

    class Queue is needed

    for the association (canhave state/methods

    needed to implement thealgorithm)

    Elevator

    ControllerElevator

    Queue

    4controls

    controlled by

    Example 8

  • 7/31/2019 Um Land Classes

    57/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Example 8

    A reservation on a passanger train consists of a

    passanger (for whom the seat is reserved), a seat(which is being reserved), and a train (time ofreservation). Besides such simple reservations, groupreservations are also allowed. Who will actuallyoccupy which seat is left over to the group.

    57

    Example 9: ternary associations

  • 7/31/2019 Um Land Classes

    58/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 58

    Example 9: ternary associations

    ternary association

    Train

    datenumber

    Seat

    CarriageNumberNumber

    1..*1

    Passengername

    title

    1..*

    Reservation

    n-ary associations

  • 7/31/2019 Um Land Classes

    59/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    n-ary associations

    Associations in general relate n classes

    Most of them are binary, but three (as in previousexample) or more are possible

    Can usually be transformed in binary associations:

    59

    Train

    datenumber

    Seat

    CarriageNumberNumber

    1..**1 *

    Passengername

    title

    1..*

    *

    Reservation

  • 7/31/2019 Um Land Classes

    60/73

    Composition Aggregation`

  • 7/31/2019 Um Land Classes

    61/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 61

    The parts can only exist if the whole exists

    they are destroyed with the whole

    Composition Aggregation

    * Text

    Window

    Listbox

    Button

    Menu*

    *

    *

    Composition Aggregation

  • 7/31/2019 Um Land Classes

    62/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 62

    Other notations expressing the same:

    Composition Aggregation

    * Text

    Window

    Listbox

    Button

    Menu*

    *

    *

    Contains

    Window

    Text

    Listbox

    Button

    Menu

    *

    *

    *

    *

    Shared Aggregation

  • 7/31/2019 Um Land Classes

    63/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 63

    Shared Aggregation

    Part may be part of several wholes

    * *

    MembersTeam Person

    * {ordered} *

    Contains

    Remix Sound clips

    * : shared aggregation

  • 7/31/2019 Um Land Classes

    64/73

    Recap: associations

  • 7/31/2019 Um Land Classes

    65/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 65

    Recap: associations

    Connect classes

    between 1, 2, 3, ... classes

    Can contain multiplicities, directions, role names

    Constraints can be used to express additionalrequirements (more on constraints later)

    Association classes can be used for more difficult

    associations that have behaviour from their ownAggregation: part-whole composition

    Generalization

  • 7/31/2019 Um Land Classes

    66/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 66

    Inheritance, is-a relationship

    The more specific may be used where the moregeneral is allowed

    Remember : Using Inheritance for code reuse, or justbecause it looks nice is a dangerous practice !

    Generalization

    Boat TruckCar

    Vehicle

    Refinement

  • 7/31/2019 Um Land Classes

    67/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 67

    Refinement

    A relationship that represents a fuller specification of

    something that has already been specified at a certainlevel of detail.

    Usefull for modelling

    a relation between the analysis version and the designversion, or between a clean implementation and anoptimized but potentially difficult variation

    A B

    B refines A

    Class refinement examples

  • 7/31/2019 Um Land Classes

    68/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 68

    Class refinement examples

    Segment

    length: Numberstretch(k : Integer)

    Segment'

    xInitial: NumberxFinal: Numberstretch(k : Integer)

    length = xFinal - xInitial

    Person

    name: Stringaddress: AddresslivesIn(location: String) : BooleanaddresStreetName : StringfirstName: StringlastName: StringprintOn(Stream s)Person

    Realization

  • 7/31/2019 Um Land Classes

    69/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 69

    Realization

    A semantic relationship between classifiers in which

    one classifier specifies a contract that anotherclassifier guarantees to carry out

    realization

    IRuleAgent

    addRule()

    changeRule()

    explainAction()

    AccountBusinessRules

    service

    description implementor

    Implementing realization

  • 7/31/2019 Um Land Classes

    70/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Implementing realization

    In Java: implemented with interfaces

    In C++: implemented with fully abstract classes

    70

    IRuleAgent

    addRule()

    changeRule()

    explainAction()

    AccountBusinessRules

    IRuleAgent

    addRule()changeRule()explainAction()

    AccountBusinessRules

    Take care

  • 7/31/2019 Um Land Classes

    71/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006

    Take care

    In older versions of UML, the notation of refinement

    was the notation which is now used for realization

    71

    Wrap-up

  • 7/31/2019 Um Land Classes

    72/73

    Roel Wuyts - ULB - Gnie logiciel et gestion de projets - 2005/2006 72

    Wrap up

    Class Diagrams model statical elements (classes and

    their relationships)

    For use by architects and developers

    Relations between classes:

    association

    aggregation

    composition aggregation

    refinement

    realization

    inheritance

    Wrap-up

  • 7/31/2019 Um Land Classes

    73/73

    UML models all kinds ofsystems.

    It is a modelling language, not a process!

    It consists of

    Views (5)

    Diagrams (9)

    It is based on a meta model and hence the different

    diagrams share similar elements

    and they are extensible

    Wrap up