OOPs Unit 2_Notes
OOPs Unit 2_Notes
UNIT -2
Page 1
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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.
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.
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.
Page 4
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Ans :
Page 5
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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 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 :
Page 6
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Analysis packages contain: use cases analysis classes , use case realizations
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.
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.
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.
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.
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
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.
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
Page 10
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
• 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.
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.
Page 12
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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.
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
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.
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).
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.
(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.
Page 16
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Ques 19. Draw the use case diagrams 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.
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.
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”
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.
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.
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:
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.
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
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.
Page 23
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Page 24
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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.
Page 25
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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:
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.
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.
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.
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.
6. There may be a chance of losing some amount of information while implementing a collaboration diagram with
respect to the sequence diagram.
Page 27
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Ques 26. Draw the collaboration diagrams for the following scenarios:
(i) ATM transactions (ii) Telephone dialing
Page 28
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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
Page 29
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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.
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.
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 :
Page 31
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Ques 29. Draw the activity diagrams for the following use cases:
Page 32
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
(ii)
Ques 30. What is event action handling in UML? Explain various types of event handlings.
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.
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.
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
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.
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
Page 37
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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.
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.
All elements of Library Domain package are public except for Account
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
(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.
Page 40
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
• 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.
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
(c)Model could be notated as a package with the keyword «model» placed above the name of the model.
Stereotyped model Layered Service:
Page 42
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Bi-directional relationship
Uni-directional relationship
Page 43
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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
Page 44
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Ans :
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.
Page 45
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
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.
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.
Following are some artifacts that are needed to be identified before drawing a component diagram:
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
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
Page 49
OBJECT ORIENTED PROGRAMMING ( UNIT 2)
Page 50