Class Diagrams 30 34

download Class Diagrams 30 34

of 34

Transcript of Class Diagrams 30 34

  • 8/8/2019 Class Diagrams 30 34

    1/34

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    2/34

    A class defines the methods and variables in anobject, which is a specific entity in a program or the unit of code representing that entityIn an object oriented application, classes have

    attributes (member variables), operations (member functions) and relationships with other classes

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    3/34

    C lass diagram in the Unified Modeling Language(UML) is a type of static structure diagram thatdescribes the structure of a system by showing thesystem's classes, their attributes, and therelationships between the classes.UML modeling elements in class diagrams

    1. C lasses and their structure and behavior

    2. Association, aggregation, and inheritancerelationships

    3. Multiplicity and navigation indicators4. Role names

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    4/34

    C lass N AME

    Attribute

    operation()

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    5/34

    Top most compartment contains the name of theclassMiddle compartment contains a list of attributes(member variables)The bottom compartment contains a list ofop erati o ns (member functions).

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    6/34

  • 8/8/2019 Class Diagrams 30 34

    7/34

    Cl ass name

    Data members

    Instance meth od s

    ArgumentsReturn ty p es

    Data members, arguments and methods are specified byvisibility name : type

    Cl ass meth od

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    8/34

    An attribute is a p rop erty of a c lass. It d escribes arange of values that the property may hold inobjects of the class.

    An operation is something that a class can do, or that you (or another class) can do to a class. Likean attribute name, an operations name is writtenin lowercase letter

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    9/34

    An instance represents a phenomenon.The name of an instance is underlined and cancontain the class of the instance.The attributes are represented with their v alues .

    zone2price = {{1, .20},{2, .40},{3, .60}}

    tariff_1974:TarifSchedule

  • 8/8/2019 Class Diagrams 30 34

    10/34

    V isibi lity - V isibi lity a pp lies t o attributeso r op erati o ns an d specifies the extent towhich other classes can use a givenclasss attributes or operations. Threelevels of visibility are possible (lastsymbols are used in UML classes toindicate different levels of visibility)

    p ub lic leve l - usabi lity exten d s t o o ther c lasses ( + )

    p ro tecte d leve l - usabi lity is op eno n ly t o c lasses that inherit fromoriginal class ( # )

    p rivate leve l - o n ly the o rigina l

    c lass can use the attribute or operation ( - ) lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    11/34

    A multiplicity in a class specifiesthe number of instances(objects) of that class that canexist simultaneously

    Example:- Only one Libraryobject is allowed in the system(referred to as a singletonobject).

    Default multiplicity is 0 or more(if not specified)

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    12/34

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    13/34

    Top 1. objectName: C lassName underlined

    2. :C lassName underlined

    Bottom Attribute names and values.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    14/34

    C lasses can related to each other through differentrelationships

    Association (delegation)Generalization (inheritance)Realization (interfaces)

    Dependency

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    15/34

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    16/34

    Association describes a link, a link being aconnection among objects between classes.

    Association is shown by a solid line betweenclasses.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    17/34

    A Person works for a C ompany

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    18/34

    Name:-Name of the association(works for Is the name ofthe relationship)Role :- The specific role of the association(Person plays the

    role employee and the C ompany plays the role employer.)Multiplicity:-Indicates the number of objects that areconnected(Many employees to one company.)Type:-Plain association, aggregation, composition( This showsa plain association)

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    19/34

    Multiplicity on association specify properties of thenumber of links that can exist between instances(objects) of the associated classes.

    That is, it indicates how many objects of one classrelate to one object of another class. It is indicatedby a single number or a range of numbers.

    We can add multiplicity on either end of classrelationship by simply indicating it next to the classwhere the relationship enters.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    20/34

    A Student can take up to five C ourses.Student has to be enrolled in at least one course.Up to 300 students can enroll in a course

    A class should have at least 10 students

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    21/34

  • 8/8/2019 Class Diagrams 30 34

    22/34

    Multiplicity Indicators

    Exactly one 1

    Zero or more (unlimited) * (0..*)

    One or more 1..*

    Zero or one (optional association) 0..1

    Specified range 2..4

    Multiple, disjoint ranges 2, 4..6, 8

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    23/34

    A special form of association that models a whole-part relationship between an aggregate (thewhole) and its parts.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    24/34

    A strong form of aggregation The whole is the sole owner of its part.

    x The part object may belong to only one whole

    Multiplicity on the whole side must be zero or one. The life time of the part is dependent upon the

    whole.x The composite must manage the creation and

    destruction of its parts.

    C ircle Point

    3..*

    1

    PolygonPoint

    C irc le

    Intro | C lasses | Re lati o ns | Generalization | Objects |lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    25/34

    AggregationAggregation CompositionComposition

    P art can be shared by severalwholes

    P art is always a part of asingle whole

    P arts can live independently (i.e.,whole cardinality can be 0..*)

    P arts exist only as part of thewhole. When the wall isdestroyed, they aredestroyed

    Whole is not solely responsiblefor the object

    Whole is responsible andshould create/destroy theobjects

    0..4category document

    *Window Frame

    *

  • 8/8/2019 Class Diagrams 30 34

    26/34

    Indicates that objects of the specialized class(subclass) are substitutable for objects of thegeneralized class (super-class).

    is kind of relationship.

    Shape{abstract}

    C ircle

    Super C lass

    SubC lass

    An abstractclass

    Generalizationrelationship

    {abstract} is atagged value thatindicates that the classis abstract.The name of anabstract class shouldbe italicized

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    27/34

    A sub-class inherits from its super-class Attributes Operations Relationships

    A sub-class may Add attributes and operations Add relationships Refine (override) inherited operations

    A generalization relationship may n o t be usedto model interface implementation.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    28/34

    Notated by a dotted lineThe most general relation between classes

    Indicates that an object affects another object

    Acc o untingSystem

    creates a Recei p tobject

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    29/34

    C onstrains are simple properties of associations,classes and many other things in UMLC onstraints are semantic restrictions noted asBoolean expressions.

    UML offers many pre-defined constraints.

    id: long { value > 0 }

    C ustomer Order *1 { total < $50 } may becancele

    d

    C onstraint Note

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    30/34

    A stereotype represents a refinement of an existing modeling conceptand is defined within a UML profile informally, a collection of relatedstereotypes, tags, and constraints to specialize the use of the UML for aspecific domain or platform, such as a UML profile for projectmanagement or for data modeling.

    The stereotype declares a set of tags, using the attribute syntax. Whenan element (such as the Square class) is marked with a stereotype, allthe tags apply to the element, and can be assigned values.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    31/34

    In the UML, the specific implementation or algorithm of an operation for a class. Informally, thesoftware procedure that can be executed inresponse to a message.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    32/34

    UML keyword is a textual adornment to categorize amodel element. For example, the keyword tocategorize that a classifier box is an interface is

    interface.

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    33/34

    DVD Movie VHS Movie V ideo Game

    R ental Item

    Rental Invoice

    1..*1

    Customer

    Checkout S creen

    0..1

    1

    SimpleAssociation

    C lass

    AbstractC lass

    SimpleAggregation

    Generalization

    C omposition

    Multiplicity

    lecture 30-34, chitkara university

  • 8/8/2019 Class Diagrams 30 34

    34/34

    Define the detailed design of each subsystem/component

    lecture 30-34, chitkara university