i219 Software Design Methodology
3. Static modeling
Kazuhiro Ogata (JAIST)

2

Outline of lecture
Some UML notations for static modeling:• Class• Stereotype• Note• Relationship• Class diagram• Static attribute & method• Qualification• Template (parameterized) class• Object• Object diagram3Class (1)• A class is described as a rectangle that has threepartitions.
name of classlist of attributes
list of methods
Note that what are written in the 3rd partition are called
operations, and the implementation of an operation is calleda method in UML.
In this course, however, terminology “method” is used insteadof “operation”.

4Class (2)• Let us consider a class of maps that associate
integers with strings with lists of pairs of strings
and integers.
namelist of attributes
list of methods

5Class (3)• An attribute is written as follows:
visibility nameOfAttribute : class (or type) = defaultValue visibility is one of -, +, # and ~ meaning private, public,protected, and package; optional (can be omitted).
 nameOfAttribute is used to refer to the attribute.
 class (or type) is a class (or type) that is the range of theattribute; optional.
 deafultValue is the initial value of the attribute; optional.
Note that an attribute may have multiplicity and {property-string} meaning
how many attribute objects or values an object of that class may have andadditional properties; e.g., {readOnly} specifies that the attribute cannot bemodified.

6Class (4)• One attribute in MapOfStringToInteger:-list: ArrayList<PairOfStringAndInteger>
In this course, visibility is always - (private), preventing fromdirectly accessing attributes from other classes (evensubclasses).
If an attribute in a class C needs to be accessed by otherclasses, C provides a getter (a get method) and a setter (a setmethod) with which the attribute can be observed andmodified.

7Class (5)Instead of p1:class1, ..., pn:classn, we may
write class1 p1, ..., classn pn in this course.

• A method is written as follows:

visibility nameOfMethod(p1:class1, …, pn:classn) : class visibility is one of -, +, # and ~ meaning private, public,protected, and package; optional.
 nameOfMethod is used to refer to the method.
 pi:classi is a parameter where pi is the name and classi is itsclass (or type); the parameter list is optional.
 class is the class (or type) of an object (or value) returned bythe method; optional.
Note that a method may have {property-string} meaning additional
properties; a parameter may be preceded by direction that is one of in(if omitted), out, and inout; it may have a default value.

8Class (6)• Five methods in MapOfStringToInteger:+put(k:String,v:Integer): Void+get(k:String): Integer+delete(k:String): Void+isRegistered(k:String): Boolean-findIndex(k:String): Integer
In this course, visibility is either - (private) or + (public); if amethod does not return any objects (values), Void is used.
The getter and setter of the attribute list are not provided andthen the attribute cannot be accessed by other classes.

9Class (6)• The 2nd & 3rd partitions (attributes & methods) in aclass may be omitted.
• A class may have an extra partition in which its
responsibilities are written.
• Some (or all) of attributes and/or methods may beomitted (which may be indicated with an ellipsis “…”).

omission of some methods

an extra partition

10

Class (7)• Abstract classes where some methods (calledabstract methods) are not implemented aredescribed in the same way as (concrete) classes
except that names & abstract methods arewritten in italics.
in italics

abstractmethods

11

Stereotype• Some specific classes, such as those for exceptions areindicated with stereotypes whose names are enclosed bydouble angle brackets (guillemets); stereotypes are also
used to describe some data types, such as enumerations,and interfaces.
stereotype

12Note• A note can be used to give comments orconstraints to an element or a collection ofelements.

note13

Relationship (1)• Four kinds of relationships among classes (& others):
1. Dependency – a change to a class (the dependee) may affect theother class (the depender); written as follows:(depender)(dependee)

2. Association – a structural relationship among classes that describes
a set of links, a link being connections of objects of those classes;
written as follows: multiplicity (optional)
0..10 or 1employer*employee

0 or more

end name (optional)

Multiplicity : m .. n (greater than or equal m & less than or equal n), * (0 ormore; the same as 0 .. *), n (exactly n; the same as n .. n)

14

Relationship (2)3. Generalization – a specialization/generalization relationship such as
inheritance; written as follows:(specializationsuch as a subclass)(generalizationsuch as superclass)

4. Realization – an implementation/specification relationship between
two things; one specifies a contraction that the other guarantees tocarry out; written as follows:(implementationsuch as a class)(specification suchas an interface)

15

Class diagram (1)• A class diagram consists of classes (and others such asinterfaces) and relationships among them.
Attributes may be described with associations.
An end name may be adorned with a visibility.

For each object of
MapOfStringToInteger, there exists
one object ofArrayList<PairOfStringAndInteger>.

For each object ofArrayList<PairOfStringAndInteger>, there exists
zero or one object of MapOfStringToInteger; there
may exists some list objects that any map objects
do not have.

16

Class diagram (2)• What the diagram describes on the previous pageis also described as follows:This specifies that pairs associated with a map
should be ordered.

17Class diagram (2)Let us consider a map such that the effect of put(…) can beundone once; the corresponding class is made to extend
MapOfStringToInteger.

18

Class diagram (3)• Let us implement ExpParseTree with two classes
NumParseTree & AddParseTree.

19

Class diagram (4)• Let us consider an arithmetic calculator that takes anexpression written as a string, converts it into a list oftokens, makes a parse tree from the list, calculates theexpression, and displays the result; the calculator
depends on parse trees.

20

Class diagram (5)• Provided (implemented) interfaces are describedas follows:• Required interfaces are described as follows:21

Class diagram (5)• A simplified version of the diagram on theprevious, previous page is described as follows:

22

Class diagram (6)• Composition
composite

component

The multiplicity on the composite side is 1 or 0..1 (which is often
omitted) b/c a component class is designed s.t. a component canhave at most or only one composite as its owner.
When a composite is destructed, so do all of its components.

• Aggregation

StmParseTree
implements ParseTree

ExpParseTree specializes23(or extends) ParseTree

Class diagram (6) AddParseTree

implements ExparseTree• An example from an assignment calculator

AssignParse Tree specializes(or extends) StmParseTree
24

Static attribute & method• Static attributes & methods in a class are sharedby all objects of that class.
• Underlines are used to specify static attributes &methods.
property string
staticattributestaticmethodsaying that theattribute cannot be
modified once it isinitialized.

25

Qualification• The design of MapOfStringToInteger was dependent
on lists.
• Qualification lets us make the design more abstract.
qualifierqualified association

For each map and each string, there exists at most one integer.

26

Template (parameterized) class• Useful to describe generic things, such as generic lists
template classV

template parameters

explicit binding:an explicit way to
instantiate Pair

implicit binding:an implicit way to
instantiate Paira conventional way
to instantiate Pair

27Object• Objects are described as rectangles; names/types
are underlined; they may have attribute values.
only type iswritten

both name & class (type)are explicitly written

only name iswritten

attribute values

28

Object diagram• A snapshot of the objects in a systemlinkobjectLinks are instances of associations.
Note that the relation between
class A and class B that is used as
the type of an attribute in A isregarded as an association
between A and B in the course.

29

Summary
Some UML notations for static modeling:• Class• Stereotype• Note• Relationship• Class diagram• Static attribute & method• Qualification• Template (parameterized) class• Object• Object diagram