You are on page 1of 42

Lecture 9

Class Diagram

Systems Analysis and Modelling


(6365, 6677)
Unit Convener: Dr. Saif Dewan

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL
Lecture Outline
• Administration
• UML Class Diagram

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 2
Administration

• Assignment (Part 3) will be in Moodle in


early next week

– Report and Presentation Slides Due on: Friday 7


November 2014 at 11:55pm

– Presentation Due during: Week 13 Tutorial

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 3
Where are we?

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 4
Relationships Between OO
Requirements Models

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 5
Object Oriented Modelling

• The process of modelling the problem


domain through objects and classes of
objects.

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 6
Class Symbol
Class Name
• Single Box – Class Name
• Or Three Compartments Class Name
Attributes
– Class Name
– Attributes
Operations
– Operations

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 7
Representing Objects and
Classes
• Object: an entity with a well-defined
role in an application domain; has
state, behaviour, and identity
characteristics
• State: encompasses an object’s
properties (attributes and
relationships) and the values of those
properties
Systems Analysis and Modelling School of Information Systems and Accounting
Semester 2 2014 @ Faculty of BGL 8
Representing Objects and
Classes (continued)
• Behaviour: represents how an object
acts and reacts
• Identity: uniqueness—no two objects
are the same
• Object class (class): a logical grouping
of objects that have the same (or
similar) attributes, relationships, and
behaviours (methods)
Systems Analysis and Modelling School of Information Systems and Accounting
Semester 2 2014 @ Faculty of BGL 9
Representing Objects and
Classes (continued)
• Class diagram: a diagram that shows
the static structure of object classes,
their internal structure, and the
relationships in which they participate

• UML classes are analogous to E-R


entities.

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 10
Representing Objects and
Classes (continued)

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 11
Representing Objects and
Classes (continued)
• Operation: a function or a service that
is provided by all the instances of a
class to invoke behaviour in an object
by passing a message
• Encapsulation: the technique of hiding
the internal implementation details of
an object from its external view

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 12
Types of Operations
• Constructor: an operation that creates
a new instance of a class
• Query: an operation that accesses the
state of an object but does not alter
the state
• Update Operation: an operation that
alters the state of an object
• Class Scope Operation: an operation
that applies to a class rather than an
object instance
Systems Analysis and Modelling
Semester 2 2014
School of Information Systems and Accounting
@ Faculty of BGL 13
Representing Associations

• Association: a relationship among


instances of classes
• Association role: the name given to
the end of an association where it
connects to a class

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 14
Representing Associations
(continued)

• Multiplicity: indicates how many


objects participate in a given
relationship:
– 0..10 means minimum of 0 and maximum
of 10
– 1, 2 means can be either 1 or 2
–* means any number
• UML associations are analogous to E-R
relationships and UML multiplicities
Systems Analysis and Modelling
are analogous to E-R cardinalities.
School of Information Systems and Accounting
Semester 2 2014 @ Faculty of BGL 15
Representing Associations
(continued)

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 16
Representing Associations
(continued)

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 17
Representing Associative
Classes
• Associative class: an association that
has attributes or operations of its own
or that participates in relationships
with other classes
• UML association classes are
analogous to E-R associative entities.
• Generalization and inheritance are
implemented via
superclass/subclasses in UML and via
supertypes/subtypes in E-R.
Systems Analysis and Modelling
Semester 2 2014
School of Information Systems and Accounting
@ Faculty of BGL 18
Representing Associative
Classes (continued)

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 19
Representing Generalisation

• Abstract class: a class that has no


direct instances but whose
descendants may have direct
instances
• Concrete class: a class that can have
direct instances

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 20
Representing Generalisation
(continued)

Figure 8-32 Example of generalisations, inheritance, and constraints

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 21
Representing Generalisation
(continued)

UML Keywords:
• Overlapping: a descendant may be
descended from more than one of the
subclasses
• Disjoint: a descendant may not be
descended from more than one of the
subclasses
• Complete: all subclasses have been
specified
•Systems
Incomplete:
Analysis and Modelling some
Schoolsubclasses have been
of Information Systems and Accounting
22
Semester 2 2014 @ Faculty of BGL
Representing Generalisation
(continued)

• Class-scope attribute: an attribute of a class


that specifies a value common to an entity
class, rather than a specific value for an
instance

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 23
Representing Generalisation
(continued)

Figure 8-33 Polymorphism,


abstract operation, class-
scope attribute, and ordering

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 24
Representing Generalisation
(continued)

• Abstract operation: defines the form


or protocol of the operation, but not
its implementation
• Method: the implementation of an
operation
• Polymorphism: the same operation
may apply to two or more classes in
different ways
Systems Analysis and Modelling School of Information Systems and Accounting
Semester 2 2014 @ Faculty of BGL 25
Representing Generalisation
(continued)

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 26
Representing Aggregation
• Aggregation: a part-of relationship
between a component object and an
aggregate object
– Represented with open diamonds
• Composition: a part object that
belongs to only one whole object and
that lives and dies with the whole
– Represented with filled diamonds

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 27
Aggregation and Composition
Figure 8-34 Aggregation and composition

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 28
Object Identification

• Identify Candidate Objects and


Classes
– Nouns in source documents
– Use Cases
– Domain Experts
– Existing Systems

• Use many approaches


Systems Analysis and Modelling School of Information Systems and Accounting
Semester 2 2014 @ Faculty of BGL 29
Candidates

• Nouns may be candidate


– Classes or Employee
– Objects or John Smith
– Attributes Date of Birth
• Verbs may be candidate methods.Retire

• Sometimes nouns are just nouns,


verbs are just verbs – but none of the
above.
Systems Analysis and Modelling School of Information Systems and Accounting
Semester 2 2014 @ Faculty of BGL 30
Some Candidates Win

• Eliminate
– Synonyms
– Sets of objects (too big)
– Attributes (too small)
– States of objects
– External objects
– etc
• The rest are our classes

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 31
• Method
Methods (Operations)
– defines the behaviour of the objects

• Identify responsibilities of the class &


determine methods required or
• Identify methods from verbs
associated with the noun
• Just the behaviour important at
analysis (key methods)
Systems Analysis and Modelling School of Information Systems and Accounting
Semester 2 2014 @ Faculty of BGL 32
Relationships

• Different types of relationships


– Objects made up of smaller objects (part-
of)
– Inheritance (kind-of)
– Dependency (depends-on)
– Objects may collaborate to provide a
service
– Plain association

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 33
Different Levels of Detail
• Different Versions of the Class Diagram for
a System
– Overview (Only class names)
– Domain-level Class Diagram
(key attributes, operations, relationships)
– Complete
(all details, design & code generation
level)

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 34
Operations
Class Name

• Specify operation
operation ()
– name operation (parm1, parm2)
operation (parm : type)
– parameters or () operation (in | out | inout
– parameter data type parm)
operation (parm : type) : type
– parameter direction
– result type

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 35
Visibility

• Attributes or operations
• Public (+)
– Any class can access
• Protected (#)
– Only sub-classes can access
• Private (-)
– Only class can access

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 36
Scope
• Whether a feature appears in each instance
of the class
• Instance – each object has its own
• Classifier – one for all objects
of the class

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 37
Interfaces
• Special sort of class
<<stereotyped>>
• Collection of operations, used to specify a
service
<<interface>>
• Has no attributes
FileAccess

open
close FileAccess
read
write

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 38
Reflexive

• When same class is on both end of


the association (remember ERD)
Employee *

0..
manager
1

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 39
Sample Class Diagram

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 40
Next Week

• Activity Diagrams

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 41
Questions?

Systems Analysis and Modelling School of Information Systems and Accounting


Semester 2 2014 @ Faculty of BGL 42

You might also like