UML Introduction and Class Diagram

Embed Size (px)

Citation preview

  • 8/6/2019 UML Introduction and Class Diagram

    1/37

    08/18/05 UML 1

    Overview

    UML Introduction and Evolution

    UML Diagrams

    Class Diagram notations

    Class notation

    Attributes

    Operations

    Class relations

  • 8/6/2019 UML Introduction and Class Diagram

    2/37

    08/18/05 UML 2

    UML Introduction

    What Is the Unified Modeling Language (UML)?

    The Unified Modeling Language (UML) is the standard

    visual modeling language used for modeling businesses,software applications, and system architectures.

  • 8/6/2019 UML Introduction and Class Diagram

    3/37

    08/18/05 UML 3

    UML Introduction

    Why do we need UML as a standard?

    UML models allows us communicate unambiguously

    Understood around the world

    UML is flexible enough to support new ways of modeling as

    technologies and businesses change.

    Is the UML Proprietary?

    The UML is not proprietary

    It is an open modeling standard designed and supported bysoftware companies, consultants, other corporations, and

    governments who need and rely on this standard.

  • 8/6/2019 UML Introduction and Class Diagram

    4/37

    08/18/05 UML 4

    UML Introduction

    Is the UML Only for Object-Oriented Development?UML is used for modeling businesses, data, organizations,

    theoretical political systems, legal contracts, biological systems,languages, hardware, non-object-oriented application modeling

    such as COBOL, and many other modeling tasks.

    Why should we have to use UML for Object-Oriented

    Development?

    In an OO system, generally several components are tied

    together using what are called interfaces. To understand howthose different components interact, it is quite useful to build a

    model UML.

  • 8/6/2019 UML Introduction and Class Diagram

    5/37

    08/18/05 UML 5

    UML Evolution

    Where Did the UML Come From?

  • 8/6/2019 UML Introduction and Class Diagram

    6/37

    08/18/05 UML 6

    UML Introduction

    The UML is a language with rules for syntax and usage.

    A methodology is much more than a language with procedures

    (i.e., processes) or practices.

    Object-oriented analysis and design (OOAD) is a process,governed by specific practices.

    Is the UML a Methodology?

  • 8/6/2019 UML Introduction and Class Diagram

    7/37

    08/18/05 UML 7

    James Rumbaughs Objectory Method (OMT) had strong

    business modeling capability.

    Grady Boochs Booch method had strengths in design and

    implementation

    Ivar Jacobsons Object Oriented Software Engineering (OOSE)

    is based around the use-case concept

    UML Introduction

    Three amigos and their Methodologies?

  • 8/6/2019 UML Introduction and Class Diagram

    8/37

    08/18/05 UML 8

    It is a standards body that brought us

    CORBA

    Interface Definition Language (IDL) and

    CORBA Internet Inter-ORB Protocol (IIOP)

    In response to overwhelming need, the OMG published a Requestfor Proposal (RFP).

    Rational Software Corporation created the UML PartnersConsortium (software companies, consultants, other corporations,

    and governments who need and rely on this standard) and published

    UML 1.0.

    UML Introduction

    What is Object Management Group? How UML was

    standardized?

  • 8/6/2019 UML Introduction and Class Diagram

    9/37

    08/18/05 UML 9

    Structure Diagrams - Structure diagrams depict the static structure

    of the elements in your system.

    Class diagrams, Component diagrams, Object diagrams,

    Deployment diagrams, Composite structure, Package diagrams.

    Behavior diagrams - Depict the dynamic behavior of the elements

    in your system.

    Activity diagrams, Use case diagrams, Statechart diagrams,

    Collaboration diagrams ( in UML2.0 it is communication diagram),

    Sequence diagrams, Timing diagrams (UML 2.0), Interactionoverview diagrams (UML 2.0)

    What types of diagrams Are in the UML?

    UML Diagrams

  • 8/6/2019 UML Introduction and Class Diagram

    10/37

    08/18/05 UML 10

    Class Diagram

    Class diagram describes the static view of a system interms of classes and relationships among the classes.

    Class diagram can be used as foundation for other

    diagrams showing other aspects of the system

  • 8/6/2019 UML Introduction and Class Diagram

    11/37

    08/18/05 UML 11

    A Class in UML

    A Class notation has three compartmentsName - mandatory

    Attributes - optional

    Operations - optional

  • 8/6/2019 UML Introduction and Class Diagram

    12/37

    08/18/05 UML 12

    Modeling Visibility

    Visibility Symbol Meaning

    Private - Only the class itself can access these attributes.

    Protected # Any child class of this class can access these attributes.

    Public + Any class can access these attributes.

    Package ~ Any class in the same package can access these attributes.

  • 8/6/2019 UML Introduction and Class Diagram

    13/37

    08/18/05 UML 13

    Modeling Multiplicity

    -contracts[1..*]:Contract[0..*] or [*]

    [1..*]

    Range without

    limit

    -knownPlanets[9]:Planet[5]Specific value

    -physicianAddress[1..2]:Address[0..5]Range of values

    ExampleSymbolType

    Multiplicity applies to both attributes and associations

  • 8/6/2019 UML Introduction and Class Diagram

    14/37

    08/18/05 UML 14

    Modeling Multiplicity and ordering

    SequenceNonuniqueOrdered

    BagNonuniqueUnordered

    OrderedSetUniqueOrdered

    SetUniqueUnordered

    Collection TypeisUniqueisOrdered

    The syntax for ordering and uniqueness is as follow:[ { [, ] } ]

    ::= ordered | unordered

    ::= unique | nonunique

  • 8/6/2019 UML Introduction and Class Diagram

    15/37

    08/18/05 UML 15

    Modeling Attribute Compartment

    The syntax for attribute definition is as follow:[visibility][/] name [:type] [multiplicity] [=default] [{property-string}]

    Modeling derived attribute: using /

    Employee

    -dateOfBirth:Date

    -/age:int

  • 8/6/2019 UML Introduction and Class Diagram

    16/37

    08/18/05 UML 16

    Modeling Attribute Compartment

    [visibility][/] name [:type] [multiplicity] [=default] [{property-string}]

    Employee

    -dateOfBirth:Date

    -/age:int-employeeId:int

    -address:Address

    The attribute name is required.

    The name should be unique within the class.

    It should be as descriptive as possible.

  • 8/6/2019 UML Introduction and Class Diagram

    17/37

    08/18/05 UML 17

    Modeling Attribute Compartment

    [visibility][/] name [:type] [multiplicity] [=default] [{property-string}]

    Employee

    -dateOfBirth:Date

    -/age:int

    -sex:Boolean

    -id:int

    -address:Address

    An attribute type identifies a classifier as given below:

    A reference to a UML primitive Data Type (Integer, UnlimitedInteger,

    or String)

    An enumeration such as Boolean

    A reference to a language-specific type such as float, long in java

    A reference to another class in you system

  • 8/6/2019 UML Introduction and Class Diagram

    18/37

    08/18/05 UML 18

    Modeling Attribute Compartment

    [visibility][/] name [:type] [multiplicity] [=default] [{property-string}]

    Event

    -name:String = no default, required

    -start_date[1]:Calendar=no default, required

    -/end_date[1]:Calendar=start_date+duration_in_days

    -duration_in_days :int = 1

    -nbr_of_shows_allowed[1]:int = 1

    -nbr_of_shows_scheduled[1]:int = 1

    To protect the integrity of the system from being corrupted by missing or

    invalid values.

    We can avoid the programming language assigning default values to

    primitive type variables.

  • 8/6/2019 UML Introduction and Class Diagram

    19/37

    08/18/05 UML 19

    Modeling Attribute Compartment

    [visibility][/] name [:type] [multiplicity] [=default] [{property-string}]

    Event

    -name:String = no default {Required, 1..30 chars, spaces and punctuation allowed}

    -start_date[1]:Calendar=no default {Required, >today and valid day of operation}

    -/end_date[1]:Calendar=start_date+duration_in_days { = start_date+duration_in_days}-duration_in_days :int = 1 {>0}

    -nbr_of_shows_allowed[1]:int = 1{>0}

    -nbr_of_shows_scheduled[1]:int = 1 {>=0 and

  • 8/6/2019 UML Introduction and Class Diagram

    20/37

    08/18/05 UML 20

    Modeling Attributes Compartment

    Class-level attribute

    Ticket

    -next_ticket_nbr[1]:int=1-ticket_nbs[1]:int = assigned at creation

    A class-level attribute is also referred to as static attribute in some languages.

    UML 1.4 stated that a static or class scoped attribute is designated by underlining

    the entire definition text string.

    UML 2.0 does not exactly say that a static attribute is underlined. However it

    does define all attributes as having a Boolean attribute called isStatic.

  • 8/6/2019 UML Introduction and Class Diagram

    21/37

    08/18/05 UML 21

    Modeling Operations Compartment

    Visibility private, package, public or protected

    Name does not have to be unique within a class

    Signature of the operation name, parameter-list and return-result

    Signature of the operation is unique

    The syntax for operation notation is as follow:[visibility] name ( [parameter-list]) : [return-result] [{properties}]

  • 8/6/2019 UML Introduction and Class Diagram

    22/37

    08/18/05 UML 22

    Modeling Operations Compartment

    Event+Event(name:String, start_date:Calendar, duration:int)

    +getName()

    +getStartDate()

    +getDuration()

    +setDuration(new_duration:int)

    +cancel()

    +reschedule(new_start_date:Calendar)

    Parameter list is an ordered list of attributes that together define the input to an

    operation.

    Each parameter is defined as name : datatype

    Multiple parameters are separated with commas.

    [visibility] name ([parameter-list]

    ) : [return-result] [{properties}]

  • 8/6/2019 UML Introduction and Class Diagram

    23/37

  • 8/6/2019 UML Introduction and Class Diagram

    24/37

    08/18/05 UML 24

    Modeling Operations Compartment

    The properties element allows you to add any additional information about the

    operation that does not fit into one of the other predefined element.

    We can use it as description of the implementation for the operation as shown

    below:setDuration(new_duration:int):void {the new duration may not cause overlap

    with another scheduled event}

    [visibility] name ( [parameter-list]) : [return-result] [{properties}]

  • 8/6/2019 UML Introduction and Class Diagram

    25/37

    08/18/05 UML 25

    Class-level operation

    Ticket

    -next_ticket_nbr[1]:int=1-ticket_nbs[1]:int = assigned at creation

    A class-level operation is also referred to as static operation in some languages.

    UML 1.4 stated that a static or class scoped operation is designated by

    underlining the entire definition text string.

    UML 2.0 does not exactly say that a static operation is underlined. However it

    does define all operations as having a Boolean attribute called isStatic.

    Modeling Operations Compartment

    +getNextTicketNbr():int

  • 8/6/2019 UML Introduction and Class Diagram

    26/37

  • 8/6/2019 UML Introduction and Class Diagram

    27/37

    08/18/05 UML 27

    Abstract Classes and operations

    Abstract classes are the classes that cannot be used to create objects.

    Modeling Abstract Classes

    ProviderStatusManager ProviderStatusManager

    #processProviderStatus()

  • 8/6/2019 UML Introduction and Class Diagram

    28/37

    08/18/05 UML 28

    Interface notation

    An interface is a declaration rather than an actual class. An implementation is

    provided by the class that realizes or implements the interface.

    Modeling Interfaces

    Collection

    +add(o:Object):Boolean

    .

  • 8/6/2019 UML Introduction and Class Diagram

    29/37

    08/18/05 UML 29

    Modeling Class Relationships

    UML relationships come in three different types:

    Association is a connection between classes which means that it is also aconnection between objects of those classes. Ex:Author writes book.

    Generalization is a relationship between a more general and a more specificelement. Ex:Editorial Review is a kind of review

    Dependency is a relationship between elements, one independent and onedependent. The dependent element is called the client orsource theindependent element is called the supplier ortarget

  • 8/6/2019 UML Introduction and Class Diagram

    30/37

    08/18/05 UML 30

    Modeling Class Relationships

    A simple association

    Author Computer Uses

    Person Car

    Uses

    OwnedBy

    1..* 0..*

  • 8/6/2019 UML Introduction and Class Diagram

    31/37

    08/18/05 UML 31

    Modeling Class Relationships

    An aggregation association

    Navy WarshipsContains

    Team Personmembers

    * *

    A shared aggregation association

  • 8/6/2019 UML Introduction and Class Diagram

    32/37

    08/18/05 UML 32

    Modeling Class Relationships

    A composition aggregation association

    GeneralLedger GLAccount

    This relationship specifies that a GLAccount in a composition relationship with aparticular GeneralLedger is destroyed when that GeneralLedger is destroyed.

  • 8/6/2019 UML Introduction and Class Diagram

    33/37

    08/18/05 UML 33

    Modeling Class Relationships

    A generalization

    Provider

    Hospital Ancillary MedicalGroup ProviderNetwork Physician

  • 8/6/2019 UML Introduction and Class Diagram

    34/37

    08/18/05 UML 34

    Modeling Class Relationships

    An Usage Dependency

    A usage dependency is one in which the client requires the presence of the supplier forits correct functioning or implementation.

    Abstraction dependancy

    An abstraction dependency is one in which the client is at one level of abstraction andthe supplier is at a different level

  • 8/6/2019 UML Introduction and Class Diagram

    35/37

    08/18/05 UML 35

    Modeling Class Relationships

    Permission Dependencies

    A permission dependency (permit) signifies that the supplier grants the client

    permission to access some or all of its constituent elements.

  • 8/6/2019 UML Introduction and Class Diagram

    36/37

  • 8/6/2019 UML Introduction and Class Diagram

    37/37

    08/18/05 UML 37

    Modeling Class Relationships

    Dashed line with an open arrowheadOne class depends on anotherDependency

    Same as generalization except that the lineis dashed

    One entity is a more refined versionof another - used to show template

    instantiation

    Refinement

    Shown either using a filled diamond at the

    "composite" end or the composite

    graphically contains the "component"

    One class is composed of another. A

    special form of aggregation.

    Composition

    Unfilled diamond at the "owner" end of

    association

    One class "owns" another. A special

    form of association.

    Aggregation

    Solid line connecting the associated

    classes. Optional open arrowhead shows

    direction of navigation

    One class uses the services of anotherAssociation

    Solid line arrow with a closed arrowheadpointing to the more general classOne class is a more specializedversion of anotherGeneralization

    NotationDescriptionRelationship