You are on page 1of 24

Table of Contents

Class & Object Diagrams


Terms, concepts, modeling techniques for
Class & Object Diagrams

Class Diagram
A graphic notation for modeling classes and
their relationships.
An Object Diagram shows individual objects
and their relationships.

Values and Attributes


A value is a piece of data.
An attribute is a named property of a class that
describes a value held by each object of the class.
ExampleClass- Person
Object- JoeSmith
Attributes- Name, BirthDate, Weight
Value- 21st October, 1983 for object JoeSmith

Operations and Methods


An operation is a function or procedure that may be
applied to or by objects in a class.
ExampleClass: Window
Operation: Open, close, hide, redisplay
All objects in a class share the same operations.
Polymorphic operations: the same operation may apply
to many different classes but the same operation takes
on different forms in different classes.
A method is the implementation of an operation for a
class.

Example- the class File may have an operation print.


You could implement different methods to print ASCII
files, print binary files, and print digitized picture files.
All these methods logically perform the same taskprinting a file but; thus you may refer to them by the
generic operation print. However, a different piece of
code may implement each method.
Arguments of an operation are target object name and
values for its attributes.
The methods belonging to an operation must have the
same signature- the number and type of arguments
and the type of result value.

Link and Association


Are the means for establishing relationships among
objects and classes.
A Link is a physical or conceptual connection among
objects.
Example- JoeSmith works for Simplex Company
Most links relate two objects, but some links relate three
or more objects.
An Association is a description of a group of links with
common structure and common semantics.
Example- a Person works for a Company.
Link- relationship between objects
Association- relationship between classes.

The links of an association connect objects


from the same classes.
An association describes a set of potential
links in the same way that a class describes a
set of potential objects.

Multiplicity
Multiplicity specifies the number of instances of
one class that may relate to a single instance of
an associated class.
Constraints the number of related objects.
UML diagrams specifies multiplicity at the end of
association lines.
1
exactly one
1..*
one or more
3..5
three to five(both inclusive)

Example of one-to-one association

Association Vs Link
Link- relationship between objects
Association- relationship between classes.

Association End Names


In UML diagram we cannot only assign a
multiplicity to an association end, but we can
give it a name as well.

Association Class
An Association Class is an association that is
also a class.
Has attributes, operations and can participate
in associations.

Generalisation
Is the relationship between a class(superclass)
and one or more variations of the
class(subclass).
The superclass holds common attributes,
operations, and associations; the subclass add
specific attributes, operations, and
associations.
Is-a relationship because each instance os a
subclass is an instance of a superclass as well.

Generalization: superclass generalizes the


subclasses.
Specialization: refers to the fact that the
subclasses refine or specialize the superclass.
Inheritance: it is the mechanism for sharing
attributes, operations, and associations via the
generalization/specialization relationship.

Multiple Inheritance
The ability of a class to inherit behaviors and
features from more than one super class.

Limitation: Diamond Problem

Button
class
inherits
two
different
implementations of equals() while it has no own
implementation of the operation. When
button.equals() is called, it is unknown which
implementation- from Rectangle or from
Clickable- will be used.

Overriding Features
A subclass may override a superclass feature by
defining a feature with the same name.
The overriding feature(the subclass feature)
refines and replaces the overridden feature(the
superclass feature).
Override methods and default values of
attributes.
Never override the signature, or form, of a
feature i.e. an override should preserve attribute
type, number and type of arguments to an
operation and operation return type.

Visibility
Use visibility markers to signify who can access
the information contained within a class.
+

Public

Allows all other classes to view the marked


information

Private

Hides information from anything outside the class


partition

Protected

Allows child classes to access information they


inherited from a parent class.

Assignment--Draw class model of a Windowing system

You might also like