0% found this document useful (0 votes)
2 views

OOPs Unit 2_Notes

this is object oriented programming notes.

Uploaded by

Shikha Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

OOPs Unit 2_Notes

this is object oriented programming notes.

Uploaded by

Shikha Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

OBJECT ORIENTED PROGRAMMING ( UNIT 2)

UNIT -2

 Class &Object Diagrams: Terms, Concepts .


 Modeling techniques for Class & Object Diagrams.
 Collaboration Diagrams: Terms, Concepts, depicting a message,
polymorphism in collaboration Diagrams.

 Iterated messages, use of self in messages.


 Sequence Diagrams: Terms, concepts, depicting asynchronous messages
with/without priority, call-back mechanism, and Broadcast messages.

 Basic Behavioural Modeling: Use cases, Use case Diagrams.


 Activity Diagrams, State Machine , Process and thread.
 Event and signals
 Time diagram, Interaction diagram , Package diagram.
 Component diagrams and Deployment diagrams

B.TECH(CSE III YEAR)

Page 1
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

SHORT ANSWER TYPE QUESTIONS


Ques 1. What are attributes and operations in classes?
Ans : An attribute is a named property of a class that describes range of values that instances of theproperty may
hold.
• A class may have any number of attributes or no attributes at all. An attribute
• represents some property of the thing you are modeling that is shared by all objects of that class.
• Graphically, attributes are listed in a compartment just below the class name.
• Attributes may be drawn showing only their names,

further specify an attribute by stating its class and possibly a default initial value

Operations
• An operation is the implementation of a service that can be requested from any object of the class to affect
behavior.
• An operation is an abstraction of something you can do to an object and that is shared by allobjects
of that class.
• A class may have any number of operations or no operations at all.
Operations may be drawn showing only their names.

Ques 2. What is the state behavior and identity of object.

Ans : All the objects have a state, behavior and identity.


 State of an object - The state or attributes are the built in characteristics or properties of an object. For example,
a T.V has the size, color, model etc.

B.TECH(CSE III YEAR)

Page 2
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

 Behaviour of the object - The behaviour or operations of an object are its predefined functions. For example, a
T.V. can show picture , change channels, tune for a channel etc. in object oriented programming terminology the
behaviour is implemented through methods.
 Object identity - Each object is uniquely identifiable. For example, the fridge cannot become the T.V.

Ques 3. What are sterotypesin UML ?


Ans : Stereotypes is extensibility mechanisms in UML which allows designers to extend the vocabulary of UML in
order to create new model elements. By applying appropriate stereotypes in your model you can make the specification
model comprehensible.
A stereotyped model type can appear in a project many times. For example, when modeling an online shopping system
with use case diagram you might have multiple actors who are <<administrator>>. Same for class model, you might
have multiple <<Enum>> or <<Model>> classes.
When a stereotyped model type is being used so frequently that they become primitive building blocks in a model,
allowing to create it directly saves time in redefining it again and again

Ques 4. Define the term use case .


Ans : A use case is a typical sequence of actions that an actor performs in order to complete a given task. It models the
tasks, services, and functions required by a system/subsystem of an application. It depicts the high-level functionality of a
system and also tells how the user handles a system. Use case are helpful in implementing use case scenarios and use case
diagrams.

Ques 5. What are found and lost messages in sequence diagrams?


Ans: A Found message is used to represent a scenario where an unknown source sends the message.
It is represented using an arrow directed towards a lifeline from an end point.

B.TECH(CSE III YEAR)

Page 3
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

(a) Lost Message – A Lost message is used to represent a scenario where the recipient is not known to the system. It
is represented using an arrow directed towards an end point from a lifeline. For example: Consider a scenario
where a warning is generated.

B.TECH(CSE III YEAR)

Page 4
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 6. What are guard messages in sequence diagrams?


Ans : To model conditions we use guards in UML. They are used when we need to restrict the flow of messages on the
pretext of a condition being met. Guards play an important role in letting software developers know the constraints
attached to a system or a particular process. For example: In order to be able to withdraw cash, having a balance
greater than zero is a condition that must be met as shown below.

Ques 7. What is broadcasting in sequence diagrams?


Ans : A broadcast is sent to all the objects in the system.

Ques 8. Differentiate between structural modeling and behavioral modeling

Ans :

S.NO Structural modeling Behavioral Modeling


1 Structural modeling captures the static Structural modeling captures the dynamic
features of a system features of a system
2 Structural model represents the Behavioral model describes the interaction in the
framework for the system and this system. It represents the interaction among the
framework is the place where all other structural diagrams
components exist
3 Classes diagrams , Objects diagrams , Activity diagrams, Sequence Diagrams ,
Deployment diagrams, Package Collaboration Diagrams, Use case diagrams
diagrams, Composite structure diagram.
Component diagram

B.TECH(CSE III YEAR)

Page 5
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 9. Differentiate between Sequence Diagrams and collaboration diagrams.


Ans :

Sequence Diagrams Collaboration Diagrams

The sequence diagram represents the UML, which is The collaboration diagram also comes under the UML
used to visualize the sequence of calls in a system that is representation which is used to visualize the organization
used to perform a specific functionality. of the objects and their interaction.

The collaboration diagrams are used to represent the


The sequence diagram are used to represent the sequence structural organization of the system and the messages
of messages that are flowing from one object to another. that are sent and received.

The sequence diagram is used when time sequence is The collaboration diagram is used when object
main focus. organization is main focus.

The sequence diagrams are better suited of analysis The collaboration diagrams are better suited for depicting
activities. simpler interactions of the smaller number of objects.

Ques 10. For which type of applications sequence diagrams is most suitable .List some advantages also.
Ans :Sequence diagram is suitable for all those applications which depict the dynamic behavior with actors ,message
passing between system objects E.g: ATM system , Library management system , Online shopping systems
Few advantages of Use Case Diagrams are :

1. It explores the real-time application.


2. It depicts the message flow between the different objects.
3. It has easy maintenance.
4. It is easy to generate.
5. Implement both forward and reverse engineering.
6. It can easily update as per the new change in the system.

Ques 11. Define the terms packages and components.


Ans : (a) Package : Package is the UML mechanism for grouping things. It can be used to:
 Group semantically related elements
 Defines a “semantic boundary” in the model
 Provides units for parallel working and configuration management
 Package is used to provide an encapsulated namespace within which all names must be unique.

B.TECH(CSE III YEAR)

Page 6
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Analysis packages contain: use cases analysis classes , use case realizations

Notations for package are as below :

LONG ANSWER TYPE QUESTIONS

Ques12. What the elements are of object oriented system? What are its advantages and disadvantages?
Ans. Elements of OO System −
 Objects − An object is something that is exists within problem domain and can be identified by data
(attribute) or behavior. All tangible entities (student, patient) and some intangible entities (bank
account) are modeled as object.
 Attributes − They describe information about the object.
 Behavior − It specifies what the object can do. It defines the operation performed on objects.
 Class − A class encapsulates the data and its behavior. Objects with similar meaning and purpose
grouped together as class.
 Methods − Methods determine the behavior of a class. They are nothing more than an action that an
object can perform.
 Message − A message is a function or procedure call from one object to another. They are information
sent to objects to trigger methods. Essentially, a message is a function or procedure call from one
object to another.
Few advantages of Object Oriented Systems are as following :

 Reduced Maintenance: The primary goal of object-oriented development is the assurance that the
system will enjoy a longer life while having far smaller maintenance costs.
 Real-World Modeling: Object-oriented system tend to model the real world in a more complete
fashion than do traditional methods. Objects are organized into classes of objects, and objects are
associated with behaviors. The model is based on objects, rather than on data and processing.

B.TECH(CSE III YEAR)

Page 7
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

 Improved Reliability and Flexibility: Object-oriented system promise to be far more reliable than
traditional systems, primarily because new behaviors can be "built" from existing objects. Because
objects can be dynamically called and accessed, new objects may be created at any time. The new
objects may inherit data attributes from one, or many other objects. Behaviors may be inherited from
super-classes, and novel behaviors may be added without effecting existing systems functions.
 High Code Reusability: When a new object is created, it will automatically inherit the data attributes
and characteristics of the class from which it was spawned. The new object will also inherit the data
and behaviors from all superclasses in which it participates. When a user creates a new type of a
widget, the new object behaves "wigitty", while having new behaviors which are defined to the system.

Drawbacks of Object Oriented Programming

 Execution overhead - Derived classes can be very complex because of inheritance and polymorphism.
Once instance of a derived class is initiated all the data and functions from base classes that may not used
are carried along with it.
 High learning curve - OOP is different from traditional programming. You must develop strong base
classes and understand the functionality of class libraries before you can take advantages it.
 Difficult to establishing base classes - a good foundation must be created before you derive other
classes. Base classes have to be generic enough to meet the needs of your application and any future
upgrades to that application.

Ques 13. What are the main features of object oriented systems?
Ans. Features of Object-Oriented System:
(a) Encapsulation-Encapsulation is a process of information hiding. It is simply the combination of process
and data into a single entity. Data of an object is hidden from the rest of the system and available only
through the services of the class. It allows improvement or modification of methods used by objects
without affecting other parts of a system.
(b) Abstraction-It is a process of taking or selecting necessary method and attributes to specify the object.
It focuses on essential characteristics of an object relative to perspective of user.
(c) Relationships-All the classes in the system are related with each other. The objects do not exist in
isolation, they exist in relationship with other objects.

There are three types of object relationships −


 Aggregation − It indicates relationship between a whole and its parts.
 Association − In this, two classes are related or connected in some way such as one class works with
another to perform a task or one class acts upon other class.
 Generalization − The child class is based on parent class. It indicates that two classes are similar but
have some differences.

B.TECH(CSE III YEAR)

Page 8
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

(d)Inheritance: Inheritance is a great feature that allows to create sub-classes from an existing class by
inheriting the attributes and/or operations of existing classes.

(e) Polymorphism and Dynamic Binding : Polymorphism is the ability to take on many different forms. It
applies to both objects and operations. A polymorphic object is one who true type hides within a super or parent
class.In polymorphic operation, the operation may be carried out differently by different classes of objects. It
allows us to manipulate objects of different classes by knowing only their common properties.

Ques 14. What are the notations of Object Diagrams and class diagrams in OMT? Represent both using
a real world example.

Ans : Object Diagrams :


 Object diagrams consist of objects.
 The link in object diagram is used to connect objects.
 Objects and links are the two elements used to construct an object diagram.

After this, the following things are to be decided before starting the construction of the diagram −
 The object diagram should have a meaningful name to indicate its purpose.
 The most important elements are to be identified.
 The association among objects should be clarified.
 Values of different elements need to be captured to include in the object diagram.
 Add proper notes at points where more clarity is require

Example : The object diagram for an Order management system which The following diagram is an instance of the
system at a particular time of purchase. It has the following objects.
 Customer , Order , Special Order , Normal Order

Note: In object representation we do not show operations on objects.

B.TECH(CSE III YEAR)

Page 9
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Class Diagrams : The following points should be remembered while drawing a class diagram −

 The name of the class diagram should be meaningful to describe the aspect of the system.
 Each element and their relationships should be identified in advance.
 Responsibility (attributes and methods) of each class should be clearly identified
 For each class, minimum number of properties should be specified, as unnecessary properties will make the
diagram complicated.
 Use notes whenever required to describe some aspect of the diagram. At the end of the drawing it should be
understandable to the developer/coder.
 Visibility modes of class members must be represented.

Visibility Modes – Three Levels of Visibility Modes are described in OMT

1. Public : Any outside classifier with visibility to the given classifier can use the feature specified byprepending the
symbol +.

2. Protected : Any descendant of the classifier can use the feature; specified by prepending the symbol #.

3. Private: Only the classifier itself can use the feature; specified by prepending the symbol -.

Scope- It specifies whether the feature appears in each instance of the classifier or whether there is just asingle
instance of the feature for all instances of the classifier. In the UML, you can specify two kinds of owner scope.

1. Instance - Each instance of the classifier holds its own value for the feature.
2. Classifier - There is just one value of the feature for all instances of the classifier.
• Figure shows, a feature that is classifier scoped is rendered by underlining the feature's name

B.TECH(CSE III YEAR)

Page 10
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Class Diagram of an Order Management System

Ques 15. Explain some common mechanisms implemented in UML


Ans : COMMON MECHANISMS OF UML:

• Stereotypes, tagged values, and constraints are the mechanisms provided by the UML to add new
building blocks, create new properties, and specify new semantics.
• For example, if you are modeling a network, you might want to have symbols for routers and hubs; then
use stereotyped nodes to make these things appear as primitive building blocks.
• Similarly, if you are part of your project's release team, responsible for assembling, testing, and then
deploying releases, you might want to keep track of the version number and test results for each major
subsystem.
• Then use tagged values to add this information to your models.

B.TECH(CSE III YEAR)

Page 11
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

A note is a graphical symbol for rendering constraints or comments attached to an element or a collection of
elements. Graphically, a note is rendered as a rectangle with a dog-eared corner, together with a textualor
graphical comment.

A stereotype is an extension of the vocabulary of the UML, allowing to create new kinds of building blocks
similar to existing ones but specific to problem. Graphically, a stereotype is rendered as a name enclosed by
(<< >>) and placed above the name of another element.

A constraint is an extension of the semantics of a UML element, allowing you to add new rules or to modify
existing ones. Graphically, a constraint is rendered as a string enclosed by brackets and placed near the
associated element or connected to that element or elements by dependency relationships

Ttagged value is an extension of the properties of a UML element, allowing you to create new information in that
element's specification. Graphically, a tagged value is rendered as a string enclosed by brackets and placed below
the name of another element. That string includes a name (the tag), a separator (the symbol =), and a value (of the
tag). Specify just the value if its meaning is unambiguous, such as when the value is the name of enumeration.

B.TECH(CSE III YEAR)

Page 12
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 16. Briefly classify various modeling techniques of UML

Ans : Common modeling techniques

1. Modeling the vocabulary of a system

1) Identify those things that users to describe the problem .use crc cards and usecase based analysisto
help find these abstractions.
2) For each abstraction, identify a set of responsibilities. Make sure that each class is crisply definedand
that there is a good balance of responsibilities among all your classes.
3) Provide the attributes and operations that are needed to carry out these responsibilities for each
class
• Fig shows a set of classes drawn from a retail system, including Customer, Order, and Product. It also
includes a few other related abstractions drawn from the vocabulary of the problem, such as Shipment
(used to track orders), Invoice (used to bill orders), and Warehouse (where products are located prior to
shipment). There is also one solution-related abstraction, Transaction, which applies to orders and
shipments.

2. Modeling the Distribution of responsibilities in a System


To model the distribution of responsibilities in a System
• Identify a set of classes that work together closely to carryout some behavior.
• Identify a set of responsibilities for each of these classes.
• Look at this set of classes as a whole, split classes that have too many responsibilities into smaller
B.TECH(CSE III YEAR)

Page 13
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

abstractions, collapse tiny classes that have trivial responsibilities into larger ones, and reallocate
responsibilities so that each abstraction reasonably stands on its own.
Consider the ways in which those classes collaborate with one another, and redistribute their responsibilities accordingly
so that no class within a collaboration does too much or too little

3. Modeling Non software things :


• If you want to distinguish these things from the UML's defined building blocks, create a new building
block by using stereotypes to specify these new semantics and to give a distinctive visualcue.
• If the thing you are modeling is some kind of hardware that itself contains software, consider
modeling it as a kind of node, as well, so that you can further expand on its structure.

4. Modeling Primitive Types : At the other extreme, the things you model may be drawn directly from the
programminglanguage you are using to implement a solution. Typically, these abstractions involve primitive

types, such as integers, characters, strings, andeven enumeration types, that you might create yourself.

B.TECH(CSE III YEAR)

Page 14
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 17.What are the components to define a single use case? Explain with an example.
Ans : Various components for describing a Use Case Scenario are as following:
A).Name: Give a short, descriptive name to the use case. This should be a verb phrase describing the action the user will
do with the system. It is also useful to include a number as a unique identifier for each use case.

B.)Actors: List the actor or actors who can perform this use case. For example, in a library system both a borrower and a
librarian can check out a book.

C).Goals: Explain what the actor or actors are trying to achieve. For example, in a library system, the goal of checking
out a book would be to borrow the book in order to read it.

D).Preconditions: Describe the state of the system before the use case occurs by listing any conditions that must be true
before an actor can initiate this use case. For example, to be able to check out a book, the book must be available and the
client must not have any overdue fines.

E).Summary: Summarize what occurs as the actor or actors perform the use case. F. Related use cases. List use cases
that may be general izations, specializations, extensions or inclusions of this one. (These are explained further in these
notes.)

G). Steps: Describe each step of the use case using a two-column format, with the left column showing the actions taken
by the actor, and the right column showing the system’s responses.

H).Post conditions: What state is the system in following the completion of this use case.

Example: Briefly describe a use case for leaving a particular automated car park (parking lot).

 Use case: Exit car park, paying cash


 Actors: Car drivers
 Goals: To leave the parking lot after having paid the amount due.
 Preconditions: The driver must have entered the car park with his or her car, and must have picked up a ticket
upon entry.
 Summary: When a driver wishes to exit the car park, he or she must bring his or her car to the exit barrier and
interact with a machine to pay the amount due.
 Related use case: Exit car park by paying using a debit card

B.TECH(CSE III YEAR)

Page 15
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 18. What are the symbols used to draw Use Case Diagram ? Define extension , inclusion and generalization
in Use Case Diagram. Mention the purpose of use case diagram.

Ans : Symbols used for Use Case Diagrams:

 an actor is shown as a stick person


 a use case is shown as an ellipse.
 Lines indicate which actors perform which use cases.
 Rectangular Box for complete use case

(i) Extensions are used to make optional interactions explicit or to handle exceptional cases. Symbol : write
<<extends>> on link
Example: Describe what happens if an actor provides a wrong filename to access a given file or describes the
extra interaction that occurs if the actor decides to browse in order to locate the required file instead of simply typing
a filename.

(ii) Generalizations work the same way as in a class diagram and use the same triangle symbol:
 several similar use cases can be shown along with a common generalized use case.
 the general ‘open file’ use case has two sub use cases:
(a) ‘open file by typing name’, and
(b) ‘open file by browsing’.

(iii) Inclusions allow you to express a part of a use case so that you can capture commonality between several
different use cases. Symbol : write <<includes>> on link
For example, many different use cases might require an actor to specify a password, to browse through a list of
items, or to open a file. Rather than repeating the details of such common interactions in multiple use cases, you
can create a special use case that will be included in other use cases.

B.TECH(CSE III YEAR)

Page 16
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 19. Draw the use case diagrams for “Online Shopping System”

Ans : Use Case Diagram for Online Shopping System

The View Items is further extended by several use cases such as:
i. Search Items
ii. Browse Items
iii. View Recommended Items
iv. Add to Shopping Cart
v. Add to Wish list.

B.TECH(CSE III YEAR)

Page 17
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Checkout use case also includes the following use cases, as shown below.

i. It requires an authenticated Web Customer, which can be done by login page, user authentication cookie
("Remember me"), or Single Sign-On (SSO). SSO needs an external identity provider's participation,
while Web site authentication service is utilized in all these use cases.
ii. The Checkout use case involves Payment use case that can be done either by the credit card and external
credit payment services or with PayPal.

B.TECH(CSE III YEAR)

Page 18
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 20. What is the purpose of Use Case Modeling? Draw a use case diagram for “Train Traffic Management”

Ans : Purpose of Use Case :


 The main purpose of a use case diagram is to portray the dynamic aspect of a system.
 It accumulates the system's requirement, which includes both internal as well as external influences.
 Analyzing the requirements of a system
 High-level visual software designing
 Capturing the functionalities of a system
 Modeling the basic idea behind the system
 Forward and reverse engineering of a system using various test cases.

B.TECH(CSE III YEAR)

Page 19
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 21. What are two dimensions of sequence diagrams? Briefly explain various notions of sequence diagrams.
Ans :
(a) Object Dimension: The horizontal axis shows the elements that are involved in the Interaction. Conventionally,
the objects involved in the operation are listed from left to right according to when they take part in the
message sequence. However, the elements on the horizontal axis may appear in any order

(b) Time Dimension: The vertical axis represents time proceedings (or progressing) down the page.

Sequence Diagram Notations


1. Actors – An actor in a UML diagram represents a type of role where it interacts with the system
and its objects.

2. Lifelines –
 A lifeline is a named element which depicts an individual participant in a sequence diagram.
 So basically each instance in a sequence diagram is represented by a lifeline. Lifeline elements are located at
the top in a sequence diagram. The standard in UML for naming a lifeline follows the following format:
Object Name : Class Name
 We display a lifeline in a rectangle called head with its name and type.

The head is located on top of a vertical dashed line (referred to as the stem) as shown above. If we want to model an
unnamed instance, we follow the same pattern except now the portion of lifeline’s name is left blank.
Difference between a lifeline and an actor – A lifeline always portrays an object internal to the system whereas actors
are used to depict objects external to the system.

B.TECH(CSE III YEAR)

Page 20
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Activation: It is represented by a thin rectangle on the lifeline. It describes that time period in which an operation is
performed by an element, such that the top and the bottom of the rectangle is associated with the initiation and the
completion time, each respectively.

Messages – Communication between objects is depicted using messages. The messages appear in a sequential order on
the lifeline. Example of different types of messages:

Ques 22. Write short notes on the following:

(i) Synchronous and Asynchronous Messages in sequence diagram


(ii) Purpose of Fragments in sequence diagrams

Ans : Synchronous messages :

 A synchronous message waits for a reply before the interaction can move forward.
 The sender waits until the receiver has completed the processing of the message.
 A large number of calls in object oriented programming are synchronous.
 We use a solid arrow head to represent a synchronous message.

(b) Asynchronous Messages: An asynchronous message does not wait for a reply from the receiver.
The interaction moves forward irrespective of the receiver processing the previous message or not. We use a lined
arrow head to represent an asynchronous message.

B.TECH(CSE III YEAR)

Page 21
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Sequence fragments have been introduced by UML 2.0, which makes it quite easy for the creation and maintenance of
an accurate sequence diagram. It is represented by a box called a combined fragment, encloses a part of interaction inside
a sequence diagram. The type of fragment is shown by a fragment operator.

Types of fragments

Operator Fragment Type


Alt Alternative multiple fragments: The only fragment for which the condition is true, will execute.
Opt Optional: If the supplied condition is true, only then the fragments will execute. It is similar to
alt with only one trace.
Par Parallel: Parallel executes fragments.
Loop Loop: Fragments are run multiple times, and the basis of interaction is shown by the guard.
region Critical region: Only one thread can execute a fragment at once.
Neg Negative: A worthless communication is shown by the fragment.
Ref Reference: An interaction portrayed in another diagram. In this, a frame is drawn so as to cover
the lifelines involved in the communication. The parameter and return value can be explained.
Sd Sequence Diagram: It is used to surround the whole sequence diagram.

B.TECH(CSE III YEAR)

Page 22
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 23. (i) Draw the sequence diagram of a typical “login process”.
(i) Draw the sequence diagram of “Library management system” process
(ii)Draw the sequence diagram of “Online book Shopping” process using fragmentations.
Ans : Sequence diagram of a typical login process.

B.TECH(CSE III YEAR)

Page 23
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Sequence diagram of a Library Management System

B.TECH(CSE III YEAR)

Page 24
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Sequence diagram of a Online Book Shopping Process

Ques 24. What are collaboration diagrams? What are basic notions of it ?

Ans : The collaboration diagram is also a part of behavioral modeling under interaction diagram. This is used to show
the relationship between the objects in a system.
 Instead of showing the flow of messages, it depicts the architecture of the object residing in the system as it is
based on object-oriented programming.
 Multiple objects present in the system are connected to each other. The collaboration diagram, which is also
known as a communication diagram, is used to portray the object's architecture in the system.

B.TECH(CSE III YEAR)

Page 25
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Notations of a Collaboration Diagram

1. Objects: The representation of an object is done by an object symbol with its name and class underlined,
separated by a colon. In the collaboration diagram, objects are utilized in the following ways:

o The object is represented by specifying their name and class.


o It is not mandatory for every class to appear.
o A class may constitute more than one object.
o In the collaboration diagram, firstly, the object is created, and then its class is specified.

o To differentiate one object from another object, it is necessary to name them.


2. Actors: In the collaboration diagram, the actor plays the main role as it invokes the interaction. Each actor has its
respective role and name. In this, one actor initiates the use case.

3. Links: The link is an instance of association, which associates the objects and actors. It portrays a relationship
between the objects through which the messages are sent. It is represented by a solid line. The link helps an object
to connect with or navigate to another object, such that the message flows are attached to links.
4. Messages: It is a communication between objects which carries information and includes a sequence number, so
that the activity may take place. It is represented by a labeled arrow, which is placed near a link.

The messages are sent from the sender to the receiver, and the direction must be navigable in that particular
direction. The receiver must understand the message.

B.TECH(CSE III YEAR)

Page 26
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 25. For what type of requirements it is easy to draw collaboration diagrams ? Mention few disadvantages of
collaboration diagrams.

Ans : Following are some of the use cases enlisted below for which the collaboration diagram is implemented:

1. To model collaboration among the objects or roles that carry the functionalities of use cases and operations.
2. To model the mechanism inside the architectural design of the system.

3. To capture the interactions that represents the flow of messages between the objects and the roles inside the
collaboration.
4. To model different scenarios within the use case or operation, involving a collaboration of several objects and
interactions.

5. In the collaboration diagram, each message constitutes a sequence number, such that the top-level message is
marked as one and so on.

6. The messages sent during the same call are denoted with the same decimal prefix, but with different suffixes of 1,
2, etc. as per their occurrence.

Advantages of a Collaboration Diagram

1. It mainly puts emphasis on the structural aspect of an interaction diagram, i.e., how lifelines are connected
2. The special case of a collaboration diagram is the object diagram.
3. It focuses on the elements and not the message flow, like sequence diagrams.
4. Since the collaboration diagrams are not that expensive, the sequence diagram can be directly converted to the
collaboration diagram.

The drawback of a Collaboration Diagram

1. Multiple objects residing in the system can make a complex collaboration diagram, as it becomes quite hard to
explore the objects.

2. It is a time-consuming diagram.
3. After the program terminates, the object is destroyed.
4. As the object state changes momentarily, it becomes difficult to keep an eye on every single that has occurred
inside the object of a system.

5. The collaboration diagram is semantically weak in comparison to the sequence diagram.

6. There may be a chance of losing some amount of information while implementing a collaboration diagram with
respect to the sequence diagram.

B.TECH(CSE III YEAR)

Page 27
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 26. Draw the collaboration diagrams for the following scenarios:
(i) ATM transactions (ii) Telephone dialing

B.TECH(CSE III YEAR)

Page 28
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 27. What is activity diagram? What are its notions?

Ans : Activity diagram is basically a flowchart to represent the flow from one activity to another activity. The activity
can be described as an operation of the system.
 The control flow is drawn from one operation to another.
 This flow can be sequential, branched, or concurrent.
 Activity diagrams deal with all type of flow control by using different elements such as fork, join, etc

The main element of an activity diagram is the activity itself. An activity is a function performed by the system. After
identifying the activities, we need to understand how they are associated with constraints and conditions. Before
drawing an activity diagram, we should identify the following elements −

 Activities
 Association
 Conditions
 Constraints

B.TECH(CSE III YEAR)

Page 29
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Symbols/Notions Used in activity diagrams

Activity: The control flow of activity is represented by control nodes and object nodes that illustrates the objects
used within an activity. The activities are initiated at the initial node and are terminated at the final node.

Activity partition /swimlane: The swim lane is used to cluster all the related activities in one column or one
row. It can be either vertical or horizontal. It used to add modularity to the activity diagram. It is not necessary to
incorporate swimlane in the activity diagram. But it is used to add more transparency to the activity diagram.

(ii) Fork & Join nodes


 Forks and join nodes generate the concurrent flow inside the activity.
 A fork node consists of one inward edge and several outward edges.
 It is the same as that of various decision parameters.
 Whenever a data is received at an inward edge, it gets copied and split crossways various outward edges.
 It split a single inward flow into multiple parallel flows.

B.TECH(CSE III YEAR)

Page 30
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Initial State: It depicts the initial stage or beginning of the set of actions.

Final State: It is the stage where all the control flows and object flows end.

Decision Box: It makes sure that the control flow or object flow will follow only one path.

Action Box: It represents the set of actions that are to be performed.

Ques 28. Draw an activity diagram for an order management system with following activities:
Send order by the customer , Receipt of the order , Confirm the order Dispatch the order
Ans :

B.TECH(CSE III YEAR)

Page 31
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 29. Draw the activity diagrams for the following use cases:

(i) ATM transaction for cash withdrawal activity


(ii) Controlling an audio-animatronic device that mimics human speech and gestures.

B.TECH(CSE III YEAR)

Page 32
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

(ii)

Ques 30. What is event action handling in UML? Explain various types of event handlings.

Ans : Events and signals


• An event is the specification of a significant occurrence that has a location in time and space.
• In the context of state machines, an event is an occurrence of a stimulus that can trigger a state
transition.
• A signal is a kind of event that represents the specification of an asynchronous stimuluscommunicated
between instances.

Kinds of Events
• Events may be external or internal. External events are those that pass between the system and its
actors.
• For example: the pushing of a button and an interrupt from a collision sensor are both examplesof
external events.
• Internal events are those that pass among the objects that live inside the system. An overflowexception is
an example of an internal event.

B.TECH(CSE III YEAR)

Page 33
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Signal Event
• A signal event represents a named object that is dispatched (thrown) asynchronously by oneobject
and then received (caught) by another. Exceptions are an example of internal signal.
• Signal events may have instances, generalization relationships, attributes and operations.
Attributes of a signal serve as its parameters.
• A signal event may be sent as the action of a state transition in a state machine or the sending ofa
message in an interaction.
• Signals are modeled as stereotyped classes and the relationship between an operation and theevents
by using a dependency relationship, stereotyped as send.

Call Events
• Just as a signal event represents the occurrence of a signal, a call event represents the dispatch ofan
operation.
• Whereas a signal is an asynchronous event, a call event is, in general, synchronous.
• It means when an object invokes an operation on another object that has a state machine, controlpasses
from the sender to the receiver, the transition is triggered by the event, the operation is completed, the
receiver transitions to a new state, and control returns to the sender.

Time and Change Events : A time event is an event that represents the passage of time. In the UML you model
a time eventby using the keyword after followed by some expression that evaluates to a period of time. A change event is
an event that represents a change in state or the satisfaction of some condition. In the UML you model a change event by
using the keyword when followed by some Boolean expression.

B.TECH(CSE III YEAR)

Page 34
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Sending and Receiving Events : Signal events and call events involve at least two objects: the object that sends the
signal or invokes the operation, and the object to which the event is directed.
Signals are asynchronous, and asynchronous calls are themselves signals, the semantics of eventsinteract with the
semantics of active objects and passive objects.

Ques 31. How many types of states are in State Chart Diagrams? Explain the behavior of ATM transaction with
the help of proper state transition diagrams

Ans : The UML consist of three states:

1. Simple state: It does not constitute any substructure.


2. Composite state: It consists of nested states (sub states), such that it does not contain more than one initial state
and one final state. It can be nested to any level.
3. Sub-machine state: The submachine state is semantically identical to the composite state, but it can be reused.

B.TECH(CSE III YEAR)

Page 35
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

 Here the Serving Customer is a composite state with sequential sub states that are Customer Authentication,
Selecting Transaction, and Transaction.

Customer Authentication and Transaction are the composite states itself is displayed by a hidden
decomposition indication icon. After the transaction is finished, the Serving Customer encompasses a trigger-less
transition back to the Idle state. On leaving the state, it undergoes the exit action eject Card that discharges the
customer card.
Description of Behavior of above State Chart Diagram
 Initially, the ATM is turned off.
 After the power supply is turned on, the ATM starts performing the startup action and enters into the Self
Test state.
 If the test fails, the ATM will enter into the Out Of Service state, or it will undergo a trigger less transition to
the Idle state. This is the state where the customer waits for the interaction.
 Whenever the customer inserts the credit card in the ATM's card reader, the ATM state changes
from Idle to Serving Customer, the entry action read Card is performed after entering into Serving Customer state.
 Since the customer can cancel the transaction at any instant, so the transition from Serving Customer state back to
the Idle state could be triggered by cancel event.

B.TECH(CSE III YEAR)

Page 36
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 32. Draw the state transition diagram for the following systems:
(i)Air Cooling System (ii) Paper printing machine

Ans : (i) State transition diagram for “ Air cooling system”

(ii) State transition diagram for “ Paper printing system”

B.TECH(CSE III YEAR)

Page 37
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 33. What are timing diagrams?


Ans : It consists of a graph or waveform that depicts the state of a lifeline at a specific point of time. It illustrates how
conditions are altered both inside and between lifelines alongside linear time axis.
The timing diagram describes how an object underwent a change from one form to another. A waveform portrays the flow

among the software programs at several instances of time.

Following are some important key points of a timing diagram:

1. It emphasizes at that particular time when the message has been sent among objects.
2. It explains the time processing of an object in detail.
3. It is employed with distributed and embedded systems.
4. It also explains how an object undergoes changes in its form throughout its lifeline.
5. As the lifelines are named on the left side of an edge, the timing diagrams are read from left to right.
6. It depicts a graphical representation of states of a lifeline per unit time.

Ques 34. What are packages in UML ? What are the variations in package diagrams?

Ans : A package is used to group elements, and provides a namespace for the grouped elements. A package is a
namespace for its members, and may contain other packages. Owned members of a package should all be package
elements. Package can also be merge with other package, thus provide the hierarchical organization of the package.

 The members of the package may be shown within the boundaries of the package.
 The elements that can be referred to within a package using non-qualified names are: Owned Element, Imported
Element, and elements enclosing namespaces.

B.TECH(CSE III YEAR)

Page 38
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

 Owned and imported elements may have a visibility that determines whether they are available outside the
package.

A package diagram in the Unified Modeling Language depicts the dependencies between the packages that
make up a model.

 Package diagram shows the arrangement and organization of model elements in middle to large scale project.
 Package diagram can also show both structure and dependencies between sub-systems or modules.

• Access: An element import is defined as a directed relationship between an importing namespace and a
packageable element.
• Dependency: A dependency is a relationship that signifies that a single or a set of model elements requires other
model elements for their specification or implementation.
• Import: A package import is defined as a directed relationship that identifies a package whose members are to be
imported by a namespace.
• Merge: A package merge is a directed relationship between two packages that indicates that the contents of the
two packages are to be combined.
• Visibility of Owned and Import element.

• "+" for public and "-" for private or helper class.

All elements of Library Domain package are public except for Account

B.TECH(CSE III YEAR)

Page 39
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 35. Elaborate various types of relationships , dependencies in package diagrams with the help of diagrams.
Ans : Various types of relationships and dependencies in package diagrams are as :
(i) Dependency (ii) Implementation (iii) Import / access (iv) Merge

(i) Dependency: Package A depends on Package B if a class in A depends on the class in B.

(ii) Packageable element is a named element that may be owned directly by a package. Owned member of the
package should all be packageable elements. If a package is removed from the model, so are all the elements
owned by the package. Package by itself is packageable element, so any package could be also a member of
the other packages.

(iii) Import/Access: The keyword «import» is shown near the dashed arrow if the visibility is public
• The keyword «access» is shown to indicate private visibility
• Public import of Page Info element and private import of Sort Info element from Domain package.

B.TECH(CSE III YEAR)

Page 40
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

The visibility of a Package Import could be either public or private.

• Package Import (Package Import) is a directed relationship between an importing namespace and imported
package
• A package import is shown using a dashed arrow with an open arrowhead from the importing namespace to
the imported package.
(iv) A package merge is a directed relationship between two packages.
• It indicates that content of one package is extended by the contents of another package.
• Package merge used when elements defined in different packages have the same name and are intended to
represent the same concept.
• Package merge is shown using a dashed line with an open arrowhead pointing from the receiving package to
the merged package.

B.TECH(CSE III YEAR)

Page 41
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

(iv) Model is a package which captures a view of a system. View of the system defined by its purpose and abstraction
level. Model is notated using the ordinary package symbol (a folder icon) with a small triangle in the upper right
corner of the large rectangle.
(a)Business Layer Model

(b)Service Layer Model

(c)Model could be notated as a package with the keyword «model» placed above the name of the model.
Stereotyped model Layered Service:

B.TECH(CSE III YEAR)

Page 42
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

(v) Package dependency diagram :


• Two types of relationship: Unidirectional and Bidirectional

Bi-directional relationship
Uni-directional relationship

B.TECH(CSE III YEAR)

Page 43
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 36.How referencing in package diagrams is done? Explain briefly


Ans : Elements can refer to other elements that are in its own package and in enclosing packages without using
Fully qualified names.

Fully qualified names : Unique global identifier like class , method , package , attribute.

Fully qualified name is composed of Qualifier which is all the names in a hierarchical sequence above the given
element and the name of element itself.

Example: 1

Example: 2

Example: 3

B.TECH(CSE III YEAR)

Page 44
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 37. Draw the package diagram of Shopping Cart Application.

Ans :

Ques 38. Explain deployment diagram with example.

Ans : The deployment diagram visualizes the physical hardware on which the software will be deployed. It
portrays the static deployment view of a system. It involves the nodes and their relationships. It maps the
software architecture created in design to the physical system architecture, where the software will be executed
as a node. Since it involves many nodes, the relationship is shown by utilizing communication paths.

The deployment diagram does not focus on the logical components of the system, but it put its attention on the hardware
topology.

Symbol and notation of Deployment diagram

The deployment diagram consist of the following notations:


1. A component
2. An artifact
3. An interface
4. A node

B.TECH(CSE III YEAR)

Page 45
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

A deployment diagram for the Apple iTunes application is given below.

The iTunes setup can be downloaded from the iTunes website, and also it can be installed on the home computer. Once
the installation and the registration are done, iTunes application can easily interconnect with the Apple iTunes store.
Users can purchase and download music, video, TV serials, etc. and cache it in the media library.

Devices like Apple iPod Touch and Apple iPhone can update its own media library from the computer with iTunes with
the help of USB or simply by downloading media directly from the Apple iTunes store using wireless protocols, for
example; Wi-Fi, 3G, or EDGE.

B.TECH(CSE III YEAR)

Page 46
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Ques 39. What is component in UML 2.0 ?What are notions of component diagram?
Ans : COMPONENT : Modular unit with well-defined interfaces that is replaceable within its environment
Autonomous unit within a system
 Has one or more provided and required interfaces
 Its internals attributes are hidden and inaccessible
 A component is encapsulated

A component diagram is used to break down a large object-oriented system into the smaller components, so as to make
them more manageable. It models the physical view of a system such as executables, files, libraries, etc. that resides
within the node.

 It helps in forming an executable system.


 A component is a single unit of the system, which is replaceable and executable.
 The implementation details of a component are hidden, and it necessitates an interface to execute a
function.
 It is like a black box whose behavior is explained by the provided and required interfaces.

Following are some artifacts that are needed to be identified before drawing a component diagram:

1. What files are used inside the system?


2. What is the application of relevant libraries and artifacts?
3. What is the relationship between the artifacts?

B.TECH(CSE III YEAR)

Page 47
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Example: Following is a component diagram for the ‘On-line Course Registration’ system. This diagram shows
conceptual view of server-side components.

Ques 40. What are Interfaces and connections established in component diagrams?

Ans : (i) Interfaces: An interface represents a declaration of a set of operations and obligations

May be shown using a rectangle symbol with a keyword <<interface>> preceding the name

A provided interface
Characterize services that the component offers to its environment
Is modeled using a ball, labelled with the name, attached by a solid line to the component
A required interface
Characterize services that the component expects from its environment
Is modeled using a socket, labelled with the name, attached by a solid line to the component
In UML 1.x were modeled using a dashed arrow

B.TECH(CSE III YEAR)

Page 48
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

(ii) Usage dependencies: This is a relationship which one element requires another element for its full
Implementation

A usage dependency is relationship which one element requires another element for its full implementation
Is a dependency in which the client requires the presence of the supplier
Is shown as dashed arrow with a <<use>> keyword
The arrowhead point from the dependent component to the one of which it is dependent

(iii) Connectors: Connect the external contract of a component to the internal structure

The ball-and-socket notation hint at that interface in question serves to mediate interactions between the two
components

 If an interface is shown using the rectangle symbol, we can use an alternative notation, using dependency
arrows

PORTS: Specifies a distinct interaction point


(a)Between that component and its environment
(b) Between that component and its internal parts
(c)Is shown as a small square symbol
(d)Ports can be named, and the name is placed near the square symbol
(e)Is associated with the interfaces that specify the nature of the interactions that may occur over a port

B.TECH(CSE III YEAR)

Page 49
OBJECT ORIENTED PROGRAMMING ( UNIT 2)

Component and Interfaces with Example:

Example : Component diagram for Student Information Application

B.TECH(CSE III YEAR)

Page 50

You might also like