UNIT II-STATIC UML DIAGRAMS
CLASS DIAGRAM
CLASS DIAGRAM
● A Class diagram is a collection of static modeling
elements such as classes and their
relationships,connected as a graph to each
other and to their contents
● UML class diagram show the classes of the
system, their inter-relationships, and the
operations and attributes of the classes
CLASS DIAGRAM
Class Diagram Notations :A class is drawn as a
rectangle with three components separated by
horizontal lines
⮚ Top compartment – class name
⮚ Middle compartment – Attributes
⮚ Bottom compartment – List of operations/methods
ClassName
attributes
operations
Student
reg no: int
name : string
Cal avg()
Attributes in a Class
● Properties of the class about which
we want to capture information
● Represents a piece of information
that is relevant to the description of
the class within the application
domain
Attributes in a Class
Only add attributes that are primitive or
atomic types
Derived attribute
● attributes that are calculated or derived from
other attributes
● denoted by placing slash (/) before name
Examples: age (subtracting birth date from current
date), GPA (calculated from grades and credit
hours)
Attributes in a Class
attributes (fields, instance variables)
Syntax: visibility name : type [count] = default_value
visibility: + public
# protected
- private
/ derived
underline static attributes
derived attribute: not stored, but can be computed
from other attribute values
attribute example:
- balance : double = 0.00
Example 1:
Example 2:
Operations in a Class
● Represents the actions or functions that a
class can perform
● Can be classified as a constructor, query,
or update operation
Operations / methods
Syntax: visibility name (parameters) : return type
visibility: + public
# protected
- private
~ package (default)
underline static methods
parameter types listed as (name: type)
omit return type on constructors and when return
type is void
method example:
+ distance(p1: Point, p2: Point): double
UML Representation of Class
Class Name
Attributes of Class
Operations/
methods of Class
Visibility of Attributes and
Operations
Relates to the level of information hiding to
be enforced.
Visibility in a class diagram:Shown on attributes and methods
● Public
One that is not hidden from any other object
Default visibility for an method
● Protected
One that is hidden from all other classes except its immediate
subclasses
● Private
One that is hidden from all other classes
Default visibility for an attribute
Visibility of Attributes and Operations
Instances of the implementing class.
-
Private
Instances of the implementing class and
its subclasses.
#
Protected
All objects within your system.
+
Public
Accessible To
Symbol
Visibility
Relationships among Classes
▪ One of primary purposes of a class diagram is
to show the relationships that classes have
with other another
▪ All systems are made up of many
classes/objects; system behavior is achieved
through the collaborations of the objects of
the system
Relationships among Classes
Represents a connection between multiple
classes or a class and itself
basic categories:
▪Association relationship
▪Generalization relationship
▪Aggregation relationship
▪Composition relationship
▪Dependency relationship
▪Realization relationship
Relationship
•Lines or arrows between classes indicate
relationships
–Association
•A relationship between instances of two classes, where one
class must know about the other to do its work,
e.g. client communicates to server
•indicated by a straight line or arrow
–Inheritance
•An inheritance link indicating one class a superclass
relationship, e.g. bird is part of mammal
•Indicated by triangle pointing to superclass
Relationship
–Aggregation
•An association where one class belongs to a collection, e.g.
instructor part of Faculty
•Indicated by an empty diamond on the side of the
collection
–Composition
•Strong form of Aggregation
•Lifetime control; components cannot exist without the
aggregate
•Indicated by a solid diamond on the side of the collection
Association Relationship
A bidirectional semantic connection between
classes
Type:
name of relationship
role that classes play in the relationship
Multiplicity of Associations
Navigability(direction of the association)
Association
19
◼Associations may optionally have the
following:
▪ Association name
◻ may be prefixed or postfixed with a small black arrowhead to indicate
the direction in which the name should be read, should be a verb or
verb phrase;
▪ Role names
◻ on one or both association ends;
◻ should be a noun or noun phrase describing the semantics of the role;
▪ Multiplicity
▪ The number of objects that can participate in an instantiated relation
▪ Navigability
Association
20
Association Relationship
Name of relationship type shown by:
▪drawing line between classes
▪labeling with the name of the relationship
▪indicating with a small solid triangle
beside the name of the relationship the
direction of the association.
Medical History
Provides
Patient
Association Relationship Role type shown by:
A role name identifies an end of an
association and ideally describes the role
played by objects in the association.
Unidirectional association
● Unidirectional association - In a unidirectional
association, two classes are related, but only
one class knows that the relationship exists.
● A unidirectional association is drawn as a solid
line with an open arrowhead pointing to the
known class.
Bidirectional (standard) association
● Bidirectional (standard) association - An
association is a linkage between two
classes.
● Associations are always assumed to be bi-
directional; this means that both classes
are aware of each other and their
relationship.
● A bi-directional association is indicated by
a solid line between the two classes.
Qualified Association
A qualified association has a qualifier that is
used to select an object (or objects) from a
larger set of related objects, based upon the
qualifier key.
For example, if a ProductCatalog contains many
ProductDescriptions, and each one can be
selected by an itemID
Qualified Association
Reflexive Association
A reflexive association is an association from
a class to itself.
Navigability
An arrow-head indicates the direction of
navigability.
E.g. Given a student object, we can easily
find all Sections the student is taking.
No arrow-head: means navigability in
both directions
Navigability
Multiplicity
Denotes the minimum number.. maximum
number of instances
Exactly one 1
Zero or more 0..* or 0..m
One or more 1..* or 1..m
Zero or one 0..1
Specified range 2..4
Multiple, disjoint ranges 1..3, 5
Generalization Relationship
● Enables the analyst to create classes
that inherit attributes and operations of
other classes
● Represented by a-kind-of relationship
Generalization
❑Generalization in the UML is shown with a solid
line and fat triangular arrow from the subclass
to superclass
●A taxonomic relationship between a more
general classifier and a more specific
classifier.
●Each instance of the specific classifier is also
an indirect instance of the general classifier.
●Thus, the specific classifier indirectly has
features of the more general classifier.
Generalization Relationship
Employee
hireDate
receivePay
performWork
Manager
Department
bonus
hireEmployee
promoteEmployee
Engineer
certifications
Analyze
design
Aggregation Relationship
⚫ Specialized form of association in which a
whole is related to its part(s)
⚫ Represented by a-part-of relationship
⚫ Aggregation is a special case of
association.
Aggregation Relationship
Denoted by placing a diamond nearest
the class representing the
aggregation
provides
Patient
Medical
History
1 0..1
Composition: A Special Case of Aggregation
⚫ Composition is shown as a solid filled
diamond, with the diamond attached to
the class that is the composite.
⚫ Composition is a form of aggregation that
requires coincident lifetime of the part
with the whole and singular ownership; i.e.
the part is owned by only one whole and is
deleted when the whole is deleted
Composition: A Special Case of Aggregation
Composition Over
Aggregation
Finge
r
0..7
Han
d
compositio
n
1
Squar
e
4
0
Boar
d
1
SalesLineIte
m
1..*
Sale
1
composition
means
-a part
instance
(Square) can only be part of
one
composit
e
(Boar
d
) at a
time
-the composite has sole responsibility for
management of
its
parts
, especially creation and
deletion
Dependency Relationship
Realization relationship
an interface realization relationship is a specialized type of
implementation relationship between a classifier and a
provided interface. The interface realization relationship
specifies that the realizing classifier must conform to the
contract that the provided interface specifies.
RELATIONSHIP IN CLASS
OOAD    UNIT II-STATIC UML DIAGRAMS.pptx
OOAD    UNIT II-STATIC UML DIAGRAMS.pptx

OOAD UNIT II-STATIC UML DIAGRAMS.pptx

  • 1.
    UNIT II-STATIC UMLDIAGRAMS CLASS DIAGRAM
  • 2.
    CLASS DIAGRAM ● AClass diagram is a collection of static modeling elements such as classes and their relationships,connected as a graph to each other and to their contents ● UML class diagram show the classes of the system, their inter-relationships, and the operations and attributes of the classes
  • 3.
    CLASS DIAGRAM Class DiagramNotations :A class is drawn as a rectangle with three components separated by horizontal lines ⮚ Top compartment – class name ⮚ Middle compartment – Attributes ⮚ Bottom compartment – List of operations/methods ClassName attributes operations Student reg no: int name : string Cal avg()
  • 4.
    Attributes in aClass ● Properties of the class about which we want to capture information ● Represents a piece of information that is relevant to the description of the class within the application domain
  • 5.
    Attributes in aClass Only add attributes that are primitive or atomic types Derived attribute ● attributes that are calculated or derived from other attributes ● denoted by placing slash (/) before name Examples: age (subtracting birth date from current date), GPA (calculated from grades and credit hours)
  • 6.
    Attributes in aClass attributes (fields, instance variables) Syntax: visibility name : type [count] = default_value visibility: + public # protected - private / derived underline static attributes derived attribute: not stored, but can be computed from other attribute values attribute example: - balance : double = 0.00
  • 7.
  • 8.
  • 9.
    Operations in aClass ● Represents the actions or functions that a class can perform ● Can be classified as a constructor, query, or update operation
  • 10.
    Operations / methods Syntax:visibility name (parameters) : return type visibility: + public # protected - private ~ package (default) underline static methods parameter types listed as (name: type) omit return type on constructors and when return type is void method example: + distance(p1: Point, p2: Point): double
  • 11.
    UML Representation ofClass Class Name Attributes of Class Operations/ methods of Class
  • 12.
    Visibility of Attributesand Operations Relates to the level of information hiding to be enforced. Visibility in a class diagram:Shown on attributes and methods ● Public One that is not hidden from any other object Default visibility for an method ● Protected One that is hidden from all other classes except its immediate subclasses ● Private One that is hidden from all other classes Default visibility for an attribute
  • 13.
    Visibility of Attributesand Operations Instances of the implementing class. - Private Instances of the implementing class and its subclasses. # Protected All objects within your system. + Public Accessible To Symbol Visibility
  • 14.
    Relationships among Classes ▪One of primary purposes of a class diagram is to show the relationships that classes have with other another ▪ All systems are made up of many classes/objects; system behavior is achieved through the collaborations of the objects of the system
  • 15.
    Relationships among Classes Representsa connection between multiple classes or a class and itself basic categories: ▪Association relationship ▪Generalization relationship ▪Aggregation relationship ▪Composition relationship ▪Dependency relationship ▪Realization relationship
  • 16.
    Relationship •Lines or arrowsbetween classes indicate relationships –Association •A relationship between instances of two classes, where one class must know about the other to do its work, e.g. client communicates to server •indicated by a straight line or arrow –Inheritance •An inheritance link indicating one class a superclass relationship, e.g. bird is part of mammal •Indicated by triangle pointing to superclass
  • 17.
    Relationship –Aggregation •An association whereone class belongs to a collection, e.g. instructor part of Faculty •Indicated by an empty diamond on the side of the collection –Composition •Strong form of Aggregation •Lifetime control; components cannot exist without the aggregate •Indicated by a solid diamond on the side of the collection
  • 18.
    Association Relationship A bidirectionalsemantic connection between classes Type: name of relationship role that classes play in the relationship Multiplicity of Associations Navigability(direction of the association)
  • 19.
    Association 19 ◼Associations may optionallyhave the following: ▪ Association name ◻ may be prefixed or postfixed with a small black arrowhead to indicate the direction in which the name should be read, should be a verb or verb phrase; ▪ Role names ◻ on one or both association ends; ◻ should be a noun or noun phrase describing the semantics of the role; ▪ Multiplicity ▪ The number of objects that can participate in an instantiated relation ▪ Navigability
  • 20.
  • 21.
    Association Relationship Name ofrelationship type shown by: ▪drawing line between classes ▪labeling with the name of the relationship ▪indicating with a small solid triangle beside the name of the relationship the direction of the association. Medical History Provides Patient
  • 22.
    Association Relationship Roletype shown by: A role name identifies an end of an association and ideally describes the role played by objects in the association.
  • 23.
    Unidirectional association ● Unidirectionalassociation - In a unidirectional association, two classes are related, but only one class knows that the relationship exists. ● A unidirectional association is drawn as a solid line with an open arrowhead pointing to the known class.
  • 24.
    Bidirectional (standard) association ●Bidirectional (standard) association - An association is a linkage between two classes. ● Associations are always assumed to be bi- directional; this means that both classes are aware of each other and their relationship. ● A bi-directional association is indicated by a solid line between the two classes.
  • 26.
    Qualified Association A qualifiedassociation has a qualifier that is used to select an object (or objects) from a larger set of related objects, based upon the qualifier key. For example, if a ProductCatalog contains many ProductDescriptions, and each one can be selected by an itemID
  • 27.
  • 28.
    Reflexive Association A reflexiveassociation is an association from a class to itself.
  • 29.
    Navigability An arrow-head indicatesthe direction of navigability. E.g. Given a student object, we can easily find all Sections the student is taking. No arrow-head: means navigability in both directions
  • 30.
  • 31.
    Multiplicity Denotes the minimumnumber.. maximum number of instances Exactly one 1 Zero or more 0..* or 0..m One or more 1..* or 1..m Zero or one 0..1 Specified range 2..4 Multiple, disjoint ranges 1..3, 5
  • 32.
    Generalization Relationship ● Enablesthe analyst to create classes that inherit attributes and operations of other classes ● Represented by a-kind-of relationship
  • 33.
    Generalization ❑Generalization in theUML is shown with a solid line and fat triangular arrow from the subclass to superclass ●A taxonomic relationship between a more general classifier and a more specific classifier. ●Each instance of the specific classifier is also an indirect instance of the general classifier. ●Thus, the specific classifier indirectly has features of the more general classifier.
  • 34.
  • 35.
    Aggregation Relationship ⚫ Specializedform of association in which a whole is related to its part(s) ⚫ Represented by a-part-of relationship ⚫ Aggregation is a special case of association.
  • 36.
    Aggregation Relationship Denoted byplacing a diamond nearest the class representing the aggregation provides Patient Medical History 1 0..1
  • 37.
    Composition: A SpecialCase of Aggregation ⚫ Composition is shown as a solid filled diamond, with the diamond attached to the class that is the composite. ⚫ Composition is a form of aggregation that requires coincident lifetime of the part with the whole and singular ownership; i.e. the part is owned by only one whole and is deleted when the whole is deleted
  • 38.
    Composition: A SpecialCase of Aggregation
  • 39.
    Composition Over Aggregation Finge r 0..7 Han d compositio n 1 Squar e 4 0 Boar d 1 SalesLineIte m 1..* Sale 1 composition means -a part instance (Square)can only be part of one composit e (Boar d ) at a time -the composite has sole responsibility for management of its parts , especially creation and deletion
  • 40.
  • 41.
    Realization relationship an interfacerealization relationship is a specialized type of implementation relationship between a classifier and a provided interface. The interface realization relationship specifies that the realizing classifier must conform to the contract that the provided interface specifies.
  • 42.

Editor's Notes

  • #4 Attributes in a Class Contains information that the analyst or user feels that the system should store Represents properties that describe the state of the object Only attributes important to the task should be included in the class For example, for employee, employee name is a good attribute; employee hair color is not (not relevant in the business application) Primitive or atomic types Such as integer, string, double, date, time, boolean, … Generally complex or compound attributes are really placeholders for relationships between classes
  • #5 Attributes in a class diagram Typed in middle compartment Derived attributes Examples: age (subtracting birthdate from current date), GPA (calculated from grades and credit hours)
  • #9 Operations in a Class Represents the actions or functions that a class can perform In later phases, the operations are converted to methods (functions in C++) Only problem domain-specific operations that are relevant to the problem should be considered Classes normally are required to provide the means to create instances, delete instances, access individual attribute values, set individual attribute values, and other basic types of operations At this point in development, don’t clutter up the definition of the class with these basic types of operations Focus only on relevant problem domain-specific operations 1)Constructor operation Creates a new instance of a class Since creation is normally available to all classes, typically will not see constructor methods at this point in the development of the class diagram 2)Query operation Makes information about the state of an object available to other objects but will not alter the object in any way 3)Update operation Changes the value of some or all of the object’s attributes which may result in a change in the object’s state
  • #11 Class representation Compartmentalized rectangles Top compartment: name of class Middle compartment: structure of the class (attributes) Bottom compartment: behavior of the class (operations)
  • #13 Operations in a Class Also can be shown on attributes Put in front of the name of the attribute or operation on the class diagram Visibility of the attribute/operation in the system Public – not hidden from any object Protected – hidden from all other classes except its immediate subclasses Private – default; hidden from all other classes
  • #15 Relationships between Classes One of primary purposes of a class diagram is to show the relationships that classes have with other another All systems are made up of many classes/objects; system behavior is achieved through the collaborations of the objects of the system
  • #18 Association Relationship An association between classes means there is a link between the objects in the associated classes Not a data flow (though data may flow in either direction across the association)
  • #21 Relationships in a class diagram Primary purpose of the class diagram is to show the relationships or associations that classes have with one another Shown by drawing lines between classes Triangle Increases the readability of the diagram Is read as “The patients provides medical history”
  • #22 Relationships in a class diagram Notice no triangle needed on a role
  • #31 Relationships in a class diagram Used because you may want to restrict the number of instances a class may have Zero/one or more use m or some other variable name when there is a specific number in the problem Specified range 2 to 4 instances Multiple, disjoint ranges 1..3, 5 == 1 to 3 or 5 instances
  • #32 Generalization Relationship The analyst creates a superclass that contains the basic attributes and operations that will be used in several subclasses. Subclasses inherit the attributes and operations of their superclass and can also contain attributes and operations that are unique just to them For example, a customer class and an employee class can be generalized into a person class by extracting the attributes and operations they have in common and placing them into a new superclass, Person Subclasses (with no children) must be concrete classes Superclasses may be abstract or concrete Encourages analyst to focus on the properties that make each class unique by allowing the similarities to be factored into superclasses Advantage: reduces redundancy in the class definitions Is represented with the a-kind-of relationship Employee is a-kind-of person Specialization relationship Flip side of generalization relationship For example, an employee class can be specialized into a manager class and an engineer class
  • #34 Point out: Attributes and operations/behavior of each class Superclass Employee class Generalization that contains attributes and operations common to all subclasses Subclass Manger and Engineer classes Specializations of a superclass hireDate, receivePay and performWork are also part of Manager and Engineer In addition to having hireDate, receivePay and performWork the class Manager also has department, bonus, hireEmployee, promoteEmployee In addition to having hireDate, receivePay and performWork the class Engineer also has certifications, analyze, and design
  • #35 Aggregation Relationship You can identify these kinds of associations when you need to use words like “is a part of” or “is made up of” to describe a relationship between classes When classes actually comprise other classes For example, CourseOffering class is a-part-of the Course class One way to recognize: are some operations on the whole automatically applied to its parts? For example, deleting a course will also delete all of its course offerings One way to recognize: is there an intrinsic asymmetry to the relationship where one class is subordinate to the other? UML notation for an aggregation relationship is an association with a diamond next to the class denoting the aggregate (whole)
  • #36 Relationships in a class diagram The medical history is “part of” the patient; it cannot exist without the patient