Object Oriented Techniques Unit 2 by Dr. Choudhary Ravi Singh
Object Oriented Techniques Unit 2 by Dr. Choudhary Ravi Singh
Class Diagrams:
A class describes the group of objects with similar properties (attributes), common
behaviour (operations), common relationship to other objects and common semantics.
Class diagram is a graphically representation used for modelling classes and their
relationships.
“The class diagram is used to model the static design view of a system. Class diagram is also
the foundation for a couple of related diagrams: component diagrams and deployment
diagrams”.
In the figure there is one class named Customer.
Customer
Name
Address
Phone
Tax()
Class diagram
Name: A class name must be unique within its enclosing package. Every class must have a
name that distinguishes it from other classes.
Attributes: A class may have any number of attributes or no attributes at all. An attribute
represents some property of the thing you are modelling, that is shared by all objects of that
class.
1
Class diagrams commonly contain the following things:
Classes, Interfaces, Collaborations, Dependency, Generalization, Association relationships.
Customer
Ram: Customer
Name
Address
:Customer
Phone
Salary()
Mohit
2
Link & Associations:
Link is a connection between the objects. It represents a simple association of one object
with another.
A link is a physical or conceptual connection between objects instances. A link is basically an
instance of association.
Example: John works for Simplex Company
An association is a group of links that have common structure and common semantics.
Example:
The Link is between two objects and the association is between two classes.
Person lives in a country....................Association
Mohan lives in India.............................Link
3
Association Classes:
An association class is "A modelling element that has both association and class
properties. An association class can be seen as an association that also has class
properties, or as a class that also has association properties".
Example:
Course
Student
Course Name
Name * Enrols for *
Course- Id
Student-Id
Fee
Address
Allocate Student ()
Check Eligibility ()
Cancel Allocation ()
Select Course ()
Update Course ()
Enrollment
Marks
Cal-Avg-Marks()
Association 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.
Course Student
Student-Id: Int
Qualified Associations
Selection of particular Student from the Course, the qualifier will be Student-Id .
4
Reflexive Association:
It occurs when a class may have multiple functions or responsibilities. For example, a staff
working in an airport may be a pilot, aviation engineer, a ticket dispatcher, a guard, or a
maintenance crew member. If the maintenance crew member is managed by the aviation
engineer there could be a managed by relationship in two instances of the same class.
Ordering:
This type of association is used to denote the set of objects at one end must appear in some
specific order.
Ordering
*Person * * Jobs
{Bag}
Sequence is a collection of objects at other end that are duplicated or appear in some
sequence.
5
4. Modelling single and multiple Inheritance.
5. Modelling Vocabulary of the System.
6. Modelling different Views of a System.
7. Forward and Reverse engineering.
Modelling Comments:
Comments are nothing but the free form observations, reviews or explanations. We can put
the comments in the Note.
If a comment is necessary then place the information in some external document and link that
document in the Note.
Discard the comments that are not important.
Responsibilities Responsibilities
Manage modelling Display the output on
of entity screen
Controller
Distribution of responsibilities
Responsibilities
Control the 6
modelling and
viewing activities
Modelling Structural Relationship:
The structural relationship can be modelled using the association class. By default the
association relationship is bidirectional but we can limit the direction and can make it
unidirectional.
Example:
1.....* 1
has
Suffering
from
*
*
* * * *
Diseases Doctor Departments
Examines Associa-
ted with
Human
name
Address
Girl Boy
name name
Address Address
7
If there is more than one parent for a class then it shows multiple inheritance.
Train
Select course()
Submit form()
Reserve seat()
Cancel seat()
Accountant Registrar
In the above set of classes there are some important classes such as student,
registrar, and course database.
8
Modelling Relationships:
Q. Prepare a class diagram from the instance diagram in the figure below:
Answer:
Class Name: Country
Attribute names: (1) Country Name (2) Population (3) Major Language (4) Capital city
(5) Per capita Income, Member function: Make border with ( )
Association name: borders with
One country can have border with zero or more Countries
9
Q. Prepare a class diagram from the instance diagram given below
Answer:
10
Q. Prepare a class diagram from the instance diagram of a geometrical document given
below; prepare the class diagram using aggregation and generalization.
Answer:
11
Draw a class diagram for school/university information/automation system.
School has
Department
Name
Generalization
Address
AddDept()
Total Students()
TotalStaff()
Examination Section
Teaching Dept NonTeachingDept
Name
Name
Name CalculateFees()
Addteacher()
Member of DisplayInfo()
AddSubject()
RemoveSubjcet()
has Library
Name
IssueBook()
Assigned to
Student
Name attends teaches
Phone Subject Teacher
Id Name
AttendClass() Salary
AttendExam() Teaching()
makeTeachingPlan()
Examination
Maintain
Name
Appears for
Date
Time
Status()
12
Draw a class diagram for hospital management system.
Has
Hospital Department
Name Name
Address interact phone
Phone
Person
TotalStaff()
Patient Has
Name Staff
Address
GetasTreated()
Doctor
Name Nurse
Test conduct
Phone Name
Name
GiveTreatment() Phone
Cost
GiveService()
13
Q. Given a figure below which represent an object diagram for a computer system for
laying out a newspaper. The system handles several pages which may contain among
other things, columns of text. The user may edit the length and width of column text,
moves it around on a page or move it to other page. Modify the object diagram to
handle this enhancement.
Answer:
User can manipulate ( manipulate is the name of the association) in three ways cut,
copy and paste .
14
Q. Prepare object diagram showing at least 10 relationships among the following object
classes. Include associations, aggregations and generalizations. Use qualified association
and show multiplicity balls in your diagrams. You need not to show the attribute or
operations. Use association name where needed.
School, playground, principal, school board, class room, book, student, teacher,
cafeteria, rest room, computer, desk, chair, ruler, door, swing.
Answer:
15
Collaboration Diagrams:
A collaboration diagram is an interaction diagram, show organisational behaviour of
objects that send and receive messages. A collaboration diagram can describe
graphically, a set of objects, relationship among those objects and the messages, that are
send and received by those objects.
Link
Classes
Objects
16
Example of a collaboration diagram:
<<Self>>
In the example of the notation for a collaboration diagram, objects are represented by rectangle
icons. Messages passed between objects are represented by labeled arrows that start with the
sending object and end with the receiving object. Where the numerical prefix to the message name
indicates its order in the sequence.
1: Question
A: Student B: Student
2: Answer
Show ()
: Canvas : Shape
17
Show () Show ()
Dao Dom
Circle: Shape : Area Triangle: Shape : Area
<<Self>
>
2. Passing the argument self and thereby telling the target object which objects
sends the message.
18
Sequence Diagram:
A sequence diagram is an interaction diagrams that describe interactions among objects in
terms of an exchange of messages over time.
UML sequence diagrams are used to show how objects interact in a given situation. An
important characteristic of a sequence diagram is that time passes from top to bottom: the
interaction starts near the top of the diagram and ends at the bottom.
Initiator
Lifelines
Messages
Activation
19
4. Message:
Messages are arrows that represent communication between objects. Use half-arrowed
lines to represent asynchronous messages. Asynchronous messages are sent from an
object that will not wait for a response from the receiver before continuing its tasks.
5. Lifelines:
Lifelines are vertical dashed lines that indicate the object's presence over time.
20
“A synchronous message is represented by full arrowhead in sequence diagram”.
Call-back Mechanism:
Call back message is a kind of that returns back to the receiving object.
Example: Request
Response
Call -back Mechanism
. .
Supplies Order
. .
21
Asynchronous Message with Priority:
1. Due to due to concurrency in messaging the target object receives multiple messages
from multiple concurrently executing sending objects.
2. These messages need to be buffered at some place. This buffer where the messages
wait for getting executed is called message queue.
3. The target object removes the message from the message queue from its front end.
4. If the message queue is overflow then the next incoming message will be rejected.
5. The message in message queue may be ordered by priority.
High Priority
msg
Target
Medium Priority msg msg msg Object
Message Buffer
Broadcasting Messages:
In some situations sender sends the message to multiple objects at a time. This sending
of messages to multiple target objects is called broadcasting of message.
1. In broadcasting, a copy of message goes into a queue of every object in the
system.
2. The stereotype <<broadcast>> is used to represent the broadcast message.
3. When the target object receives the broadcast message, it may ignore this
message if the operation that processes this message is not available.
Example: Company may broadcast salary deposition notice to employees.
C: Company : Employee
<<Broadcast>>
22
This diagram shows
many employees
Use Cases:
“Use cases are services or functions provided by the system to its users”.
Subject: The Subject denotes the purpose of the use case diagram. It is written as a text
within a rectangular boundary. The boundary is known as system boundary.
Use Cases: The set of ellipse within which some behaviour is specified.
Relationships: Illustrate relationships between an actor and a use case with a simple
line. For relationships among use cases, use arrows labelled either "include" or
"extends” or “generalization”. A "include" relationship indicates that one use case is
needed by another in order to perform a task. Base use case is dependent on the included use
case(s); without it the base use case is incomplete .An "extends" relationship indicates
alternative options under a certain use case.
23
Base use .....................................<<include>>......
Include use
case
case
TV Remote Control
Signal setting
Increment/decrem
<<include>> Mute
ent channel
Push
Button <<include>
>
<<include>>
<<include>>
On/off
menu
Increase/decrea <<include>>
se volume
<<include>>
24
Example: A use case diagram for a ATM system.
Activity Diagram:-
An activity represents an operation on some class in the system that results in a change in the state
of the system. An activity diagram illustrates the dynamic nature of a system by modelling the flow
of control from activity to activity.
An activity diagram is essentially a flow chart, showing flow of control from activity to activity.
Action Flow: Action flow arrows illustrate the relationships among action states.
25
Initial State: A filled circle followed by an arrow represents the initial action state.
Final State: An arrow pointing to a filled circle nested inside another circle represents the
final action state.
Branching: A diamond represents a decision with alternate paths. The outgoing alternates
should be labelled with a condition or guard expression. You can also label one of the paths
"else."
fork
Join
26
27
Draw collaboration, sequence, use case diagrams for a hospital management system.
1. Takes appointment
A: Patient 10. Pay fees B: Receptionist
4. Confirm appointment
9. Ask for Payment
5. Consult doctor 7. Treat 2. Takes appointment
Patient from doctor
8. Patient OK
3. Doctor available
D: Nurse
C: Doctor
6. Assist Doctor
2.
1.
4. 3.
5. 6.
7.
8.
9.
10.
28
State Machine/State Chart: A state machine is anything that can have different
states. In many cases when we are talking about states, we are talking about the
different states of an object. This diagram models the dynamic flow of control from
state to state within a system.
Sates:
States represent situations during the life of an object. You can easily illustrate a state in
Smart Draw by using a rectangle with rounded corners.
Transition
A solid arrow represents the path between different states of an object. Label the transition
with the event that triggered it and the action that results from it.
29
Initial State
A filled circle followed by an arrow represents the object's initial state.
Final State
An arrow pointing to a filled circle nested inside another circle represents the object's final
state.
30
Process and Threads:
31
1. Internal events. These are the events that are passed among the objects are resides
inside the system.
2. External events: These are the events that are passed between system and it’s
user.
Signal:
A signal is a kind of event that represents some message specification which is
communicated between objects.
Example:
Package Diagrams:
Package diagrams organize the elements of a system into related groups to minimize
dependencies among them.
32
Visibility
Visibility markers signify who can access the information contained within a package.
Private visibility means that the attribute or the operation is not accessible to anything outside
the package. Public visibility allows an attribute or an operation to be viewed by other
packages. Protected visibility makes an attribute or operation visible to packages that inherit
it only.
Dependency
Dependency defines a relationship in which changes to one package will affect another
package. Importing is a type of dependency that grants one package access to the contents of
another package.
Example:
33
Time Diagram:
Time diagram are used to explore the behaviours of objects throughout a given period of
time.
Lifeline
State: Time diagram shows many states of object that might change over the time.
States
Terminated
Running X
Waiting
Created
{20-30 sec}
34
Interaction Diagram:
Architectural Modelling:
Component Diagram:
A component diagram describes the organization of the physical components in a system.
Interface:
An interface describes a group of operations used or created by components.
Dependencies:
Draw dependencies among components using dashed arrows.
35
Example: Simple Component diagram with Interfaces: we have 3 simple components
that work together to create a whole system.
Deployment Diagrams:
Deployment diagrams depict the physical resources in a system including nodes,
components, and connections.
Basic Term and Concepts:
Component: A node is a physical resource that executes code components.
Components and Nodes: Place components inside the node that deploys them.
36
Example of a deployment diagram:
37
UML Diagram Types that we have studied:
38
39