Unit 1.3
Unit 1.3
Class modelling
Associations
Generalization/Specialization
UML Representation of Generalization/Specialization
1
Objectives
2
Class Diagram
3
Class Diagram Example
Name of class
Poly
Instance Variables
- trms[] : int
- deg : int Methods will go here
4
Operations and Methods
It is a function or procedure that may be applied to or by
objects in a class
The same operation may be applied to many different
classes such operation is called polymorphic
Operation has to be listed in the third compartment and
use lower case letter for the first letter
Parenthesis encloses argument list and colon precedes
result type
5
Poly Class Diagram
Name of class
Poly
Instance Variables
trms[] : int
deg : int Methods will go here
6
UML representation of classes/objects:
7
Values and attributes
Person Smith:Person
Name : string John:Person
Name=“Smith”
Bdate : date
Bdate=01 Jan 1999
ClassName
attributeName1:dataType1=defaultValue1
attributeName2:dataType2=defaultValue2
operationName1(argumentList1):resultType1
operationName2(argumentList2):resultType2
9
Link and Association Concepts
A link is a physical or conceptual among objects
Most link relate two objects but some links relate three
or more objects.
Association is a description of a group of links with
common structure and semantics
10
Associations
Uses
Author Computer
11
Multiplicity
12
The commonest multiplicities are:
One-to-one
tax_coding
John Smith
760901-1234
Mary Jones
691205-5678
People Tax_codes
13
One-to-many
mother_of
M.E. Meinke
K. Meinke
N. Meinke
Women
People
14
Many-to-many
parent_of
M.E. Meinke
K. Meinke
K.W. Meinke
N. Meinke
People People
15
Examples: one-to-one
1 1
Class_A Class_B
one-to-many
1 *
Class_A Class_B
16
Examples: many-to-many
* *
Class_A Class_B
17
More Normal Associations
Owned
1..* by
Person Car
Owns 0..*
18
Recursive Association
*
Node
Connects
19
Association Class
20
Association Class
Queue
Button
21
Visibility
The simple idea is that any class has public and private
and protected elements.
Public elements can be used by any other class;
private elements can be used only by the owning class.
However, each language makes its own rules. Although
many languages use terms such as "public,"
"private," and "protected," they mean different things in
different languages.
These differences are small, but they lead to confusion,
especially for those of us who use more than one
language.
22
Within the UML, you can tag any attribute or operation with
a visibility indicator.
However, the UML provides four abbreviations for visibility:
UML denotes visibility with a prefix.
+ (public) features, -- any method can freely access public
features.
- (private) features -- Only methods of the containing class
can access.
+publicAttribute: Type
-privateAttribute: Type
# protectedAttribute: Type
~ packageAttribute: Type
+publicMethod()
-privateMethod()
# protectedMethod()
~ packageAttribute()
24
Question-answer session
25
Home Work
and Specialization
26