OOSD
OOSD
OOSD
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
1 Introduction
CONTENTS
Part-1 : Introduction, The Meaning ..................... 1–2L to 1–11L
of Object Orientation,
Object Identity, Encapsulation,
Information Hiding,
Polymorphism, Generosity
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
PART-1
Introduction, The Meaning of Object Orientation, Object Identity,
Encapsulation, Information Hiding, Polymorphism, Generosity.
Questions-Answers
Answer
1. In the object-oriented approach, the focus is on capturing the structure
and behavior of information systems into small modules that combines
both data and process.
2. The main aim of Object Oriented Design (OOD) is to improve the quality
and productivity of system analysis and design by making it more usable.
3. In analysis phase, OO models are used to fill the gap between problem
and solution.
4. It performs well in situation where systems are undergoing continuous
design, adaption, and maintenance.
5. It identifies the objects in problem domain, classifying them in terms of
data and behavior.
6. Following are the benefits of object-oriented approach :
a. It facilitates changes in the system at low cost.
b. It promotes the reuse of components.
c. It simplifies the problem of integrating components to configure
large system.
d. It simplifies the design of distributed systems.
Answer
Following are the elements of object-oriented system :
1. Objects :
a. An object is something that is exists within problem domain and
can be identified by data (attribute) or behavior.
b. All tangible entities (student, patient) and some intangible entities
(bankDownloaded
account) arebymodeled as object.
KS ([email protected])
lOMoARcPSD|22022671
Answer
Features of object-oriented language are :
1. Encapsulation :
i. Encapsulation means that data are encapsulated inside an inviolable
shell along with the methods required to use it.
Object 1 Object 2
Message C
Method 2
Method 1
Data Data
Method 1
Method 5
Method 3
Method 6
Message B
Message A
ii. The only way to reach the data is through these particular methods
(see Fig. 1.3.1).
iii. It is the mechanism that binds together code and the data it
manipulates.
iv. This concept is also used to hide the internal representation, or
state, of an object from the outside.
2. Polymorphism :
i. Polymorphism means having many forms.
ii. Polymorphism is the ability of a message to be displayed in more
than one form.
iii. It plays an important role in allowing objects having different
internal structure to share the same external interface.
3. Inheritance :
i. Inheritance is the ability to create classes that share the attributes
and methods of existing classes, but with more specific features.
ii. Inheritance is mainly used for code reusability.
Answer
Steps of object-oriented design :
1. System analysis :
i. In this stage a statement of the problem is formulated and a model
is build. This phase show the important properties associated with
the situation.
ii. The analysis model is a concise, precise abstraction and agreement
on how the desired system must be developed.
iii. The objective is to provide a model that can be understood by any
application experts in the area.
2. System design :
i. At this stage, the complete system architecture is designed.
ii. In this stage the whole system is divided into subsystems, based on
system analysis model and the proposed architecture of the system.
3. Object design :
i. At this stage, a design model is developed based on the analysis
model.
ii. The object design decides the data structures and algorithms needed
to implement each of the classes in the system.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
4. Final implementation :
i. At this stage, the final implementation of classes and relationships
developed during object design takes place.
ii. Actual implementation should be done using software engineering
practice. This helps to develop a flexible and extensible system.
Answer
Answer
OR
What do you mean by object-oriented techniques ? Explain with
some examples. AKTU 2012-13, Marks 10
Answer
1. Object-Oriented Technology (OOT) is an approach to program
organization and development that attempts to reduce some of the issues
with conventional programming techniques.
2. It is a new way of organizing and developing programs and has nothing
to do with any particular programming language.
3. However, not all languages are suitable to implement the object-oriented
concepts or implement partial features of object-oriented concepts.
Pros of object-oriented technology are :
1. It allows parallel development : If we are working with programming
teams, then each can work independently of one another once the
modular classes have been worked out.
2. The modular classes are often reusable : Once the modular classes
have been created, they can often be used again in other applications or
projects.
3. The coding is easier to maintain :
a. With OOP, because our coding base has been centralized, it is easier
to create a maintainable procedure code.
b. That makes it easier to keep our data accessible when it becomes
necessary to perform an upgrade.
c. This process also improves the security of the programming since
high levels of validation are often required.
Cons of object-oriented technology are :
1. It is inefficient :
a. Object-oriented programming tends to use more CPU than
alternative options.
b. That can make it inefficient choice when there are technical
limitations involved due to the size.
2. It is scalable :
a. If OOP is out of control, then it can create a massive amount of
bloated, unnecessary code.
b. When that occurs, the overhead rises and that makes it difficult to
keep costs down.
3. It causes duplication :
a. OOP projects tend to be easier to design than implement.
b. That is because of the modular classes that are so flexible in their
application.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. Object identity is a property of data that is created in the context of an
object data model, where an object is assigned a unique internal object
identifier, or object ID.
2. The object identifier is used to define associations between objects and
to support retrieval and comparison of object-oriented data based on the
internal identifier rather than the attribute values of an object.
3. There are many techniques for identifying objects in programming
languages.
4. OO languages have built-in mechanisms for identifying objects. There
is no need to create explicit object identifier types.
5. For example : In C++ an objects actual memory address serves as a
unique identifier and can be obtained by applying the '&' operator to an
object or object reference.
6. Object identity can be tested by pointer comparison.
Answer
1. Encapsulation consists of separating the external aspects of an object,
which are accessible to other objects, from the internal implementation
details of the object, which are hidden from other objects.
2. Encapsulation prevents a program from becoming so interdependent
that a small change has massive ripple effects.
3. The implementation of an object can be changed without affecting the
applications that use it.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Methods
Answer
1. Information hiding is the process of hiding the details of an object or
function.
2. The hiding of these details results in an abstraction, which reduces the
external complexity and makes the object or function easier to use.
3. In addition, information hiding effectively decouples the calling code
from the internal workings of the object or function being called, which
makes it possible to change the hidden portions without having to also
change the calling code.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. Polymorphism means having many forms.
2. Polymorphism is the ability of a message to be displayed in more than
one form.
3. It plays an important role in allowing objects having different internal
structure to share the same external interface.
4. An operation is a function that may be applied to or by objects in a class.
5. Open, close, hide, and redisplay are operations on class Window. All
objects in a class share the same operations.
6. Each operation has a target object as an implicit argument.
7. The behavior of the operation depends on the class of its target.
8. An object “knows” its class, and hence the right implementation of the
operation.
9. The same operation may apply to many different classes. Such an
operation is polymorphic; i.e., the same operation takes on different
forms in different classes.
10. For example, the class File may have an operation print.
11. Different methods could be implemented to print ASCII files, print binary
files, and print digitized picture files.
12. All these methods logically perform the same task. However, each method
may be implemented by a different piece of code.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Applicability of polymorphism :
1. In programming languages there are two types of polymorphism ad-hoc
and universal.
2. There are two kinds of universal polymorphism: parametric and
subtyping.
3. Ad-hoc polymorphism is a kind of polymorphism in which polymorphic
functions can be applied to arguments of different types.
4. In universal (parametric) polymorphism, the polymorphic functions are
written without mention of any specific type.
5. The ad-hoc polymorphism is applicable in both traditional and object-
oriented programming environments, whereas universal polymorphism
only applies to object-oriented systems.
PART-2
Importance of Modelling, Principles of Modelling,
Object-oriented Modelling.
Questions-Answers
Answer
1. A model is an abstraction of something for the purpose of understanding
it before building it.
2. Since a model leave out non essential detail, it is easier to manipulate
them.
3. To build hardware and software systems, the developer needs to :
i. Abstract different views of the system.
ii. Build models using precise notations.
iii. Make sure that the model satisfy the requirements of the system.
iv. Add details to transform the model into an implementation.
4. Model serves the following purpose :
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Que 1.13. What are the different models used in object oriented
languages ?
OR
Write short note on dynamic modeling and functional modeling.
AKTU 2011-12, Marks 05
Answer
There are three types of models in object oriented languages are :
1. Object model :
a. The object model identifies the classes in the system and their
relationship, as well as their attributes and operations.
b. It represents the static structure of the system. The object model is
represented graphically by a class diagram.
2. Dynamic model :
a. The dynamic model indicates the dynamics of the objects and their
changes in state.
b. The dynamic model captures the functional behavior of the system
by exploring the behavior of the objects over time and the flow of
control and events among the objects.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
3. Functional model :
a. The functional model is a data flow diagram of the system and
describes what the system does, not how it is done.
b. A DFD is a network representation of the system to show the
functional relationships of the values that are computed by a system.
c. Data flow diagrams consist of processes, data flows, actors and data
stores.
Answer
a. Data store :
1. A data store is a passive object within a data flow diagram that stores
data for later access.
2. Unlike an actor, a data store does not generate any operations on its
own but merely responds to requests to store and access data.
3. A data store allows values to be accessed in a different order than they
are generated.
4. A data store is drawn as a pair of parallel lines containing the name of
the store.
5. Input arrows indicate information or operations that modify the stored
data; this includes adding elements, modifying values, or deleting
elements.
6. Output arrows indicate information retrieved from the store. This
includes retrieving the entire value or some component of it.
b. Actors :
1. An actor is an active object that drives the data flow graph by producing
or consuming values.
2. Actors are attached to the inputs and outputs of a data flow graph.
3. Examples of actors include the user of a program, a thermostat, and a
motor under computer control.
4. An actor is drawn as a rectangle to show that it is an object. Arrows
between the actor and the diagram are inputs and outputs of the
diagram.
c. Control flow :
1. A data flow diagram shows all possible computation paths for values; it
does not show which paths are executed and in what order.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Principles of modeling are :
1. The choice of what models to create has a profound influence
on how a problem is attacked and how a solution is shaped :
This means choose correct model as per the requirement of problem
statement.
2. Every model may be expressed at different levels of precision :
This means all the user and developers both may visualize a system at
different levels of details at different time.
3. The best models are connected to reality : This means that the
model must have things that are practically possible. They must satisfy
the real word scenarios.
4. No single model is sufficient, Every non-trivial system is best
approached through a small set of nearly independent models :
This means we need to have use case view, design view, process view,
implementation view and development view. Each of these views may
have structural as well as behavioral aspects. Together these views
represent a system.
Importance of modeling :
Modeling help the development team better to visualize the plan of their
system and allow them to develop more rapidly by helping them build
the right thing.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Object-oriented modeling :
1. Object-oriented modeling (OOM) is the construction of objects using a
collection of objects that contain stored values of the instance variables
found within an object.
2. Object-oriented modeling is an approach to modeling an application that
is used at the beginning of the software life cycle when using an object-
oriented approach to software development.
Steps involved in OOM process :
1. System analysis :
i. In this stage a statement of the problem is formulated and a model
is build. This phase show the important properties associated with
the situation.
ii. The analysis model is a concise, precise abstraction and agreement
on how the desired system must be developed.
iii. The objective is to provide a model that can be understood by any
application experts in the area.
2. System design :
i. At this stage, the complete system architecture is designed.
ii. In this stage the whole system is divided into subsystems, based on
system analysis model and the proposed architecture of the system.
3. Object design :
i. At this stage, a design model is developed based on the analysis
model.
ii. The object design decides the data structures and algorithms needed
to implement each of the classes in the system.
4. Final implementation :
i. At this stage, the final implementation of classes and relationships
developed during object design takes place.
ii. Actual implementation should be done using software engineering
practice. This helps to develop a flexible and extensible system.
Que 1.17. Define link and association. Discuss the role of link and
association in object modeling with suitable example.
AKTU 2012-13, Marks 05
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. Link and association in object modeling represent the relation between
objects and classes.
2. Link : Link defines the relationship between two or more objects and a
link is considered as an instance of an association.
3. Association : It is a group of links that relates objects from the same
classes.
4. For example :
i. Let us take the two classes Person and Company. Now there is an
association relation between these two classes.
ii. A person may own stock in zero or more companies.
iii. Also it can be related in reverse that a company may have several
persons owing its stock.
iv. The object diagram below shows the links between the objects of
person and company class.
jhon:Person
name=“jhon”
Marry:Person
name=“jhon” jhon:Person
name=“jhon”
James:Person
name=“jhon”
jhon:Person
Sue:Person name=“jhon”
name=“jhon”
Kriti:Person
name=“jhon”
Fig. 1.17.1.
v. The class diagram below shows the association between the person
and the company class. Both link and association are represented
with a line in UML notation.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Object modeling technique :
1. The Object Modeling Technique (OMT) is the methodology that combines
the three views of modeling system, i.e., the object model, the dynamic
model and the functioned model.
2. These three models separate a system into orthogonal views that can be
represented and manipulated with a uniform notation.
Stages of object modeling technique :
1. Analysis :
a. Starting from a statement of the problem, the analyst builds a
model of the real-world situation showing its important properties.
b. The analysis model is a concise, precise abstraction of what the
desired system must do.
c. The objects in the model should be application-domain concepts.
d. A good model can be understood by application experts who are
not programmers.
e. For example, a Window class in a workstation windowing system
would be described in terms of the attributes and operations visible
to a user.
2. System design :
a. The system designer makes high-level decisions about the overall
architecture.
b. During system design, the target system is organized into
subsystems based on both the analysis structure and the proposed
architecture.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Designing the filament for a light bulb :
1. Because the filament of a light bulb operates at a high temperature,
resistance to high temperatures is important.
2. Tungsten is generally used because of its high melting point, even though
tungsten filaments are brittle.
Designing the electrical system for an airplane :
1. Weight is important for wire that is to be used in the electrical system of
an airplane, because it affects the total weight of the plane.
2. Toughness of the insulation is important to resist chafing due to vibration.
3. Resistance of the insulation to fire is also important to avoid starting or
feeding electrical fires in flight.
PART-3
Introduction of UML, Conceptual Model of UML, Architecture.
Questions-Answers
Answer
UML :
1. UML stands for Unified Modeling Language.
2. UML is a pictorial language used to make software blueprints.
3. UML can be described as a general purpose visual modeling language to
visualize, specify, construct, and document software system.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Library
1
1
has
contains
* 1.. *
User * reserves Item
*
name Kind
0..1 title
* consults
1
has_copies
*
*
Copy
borrows
* location
status
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Que 1.21. Describe the pros and cons of unified modeling language
Answer
Pros of UML :
1. It has wide industry acceptance in comparison to previous modeling
language.
2. It supports OOAD methodology.
3. It bridges the communication gap between different entities of system
development (i.e., System Analyst, Developer, Client etc).
4. Constructed models are easy to understand, even for non-programmers.
5. It is a unified and standardize modeling language.
Cons of UML :
1. UML is often criticized as being large and complex.
2. It takes a lot of time to keep the diagram reasonable and synchronized
with the actual code.
3. You cannot represent every condition in a sequence diagram.
4. UML software costs money.
5. Complex to learn and takes time to master properly.
Que 1.22. Why UML required ? What are the basic architecture of
Answer
The UML is required to help system and software developers accomplish
the following tasks :
i. Specification
ii. Visualization
iii. Architecture design
iv. Construction
v. Simulation and testing
vi. Documentation
Basic architecture of UML :
1. The UML is defined in a circular manner, in which a subset of the
language notation and semantics is used to specify the language itself.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
2 Basic Structural
Modeling
CONTENTS
Part-1 : Basic Structural Modeling, ....................... 2–2L to 2–8L
Class, Relationships, Common
Mechanism and Diagram
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Questions-Answers
Answer
There are three important types of modeling :
1. Structural Modeling :
a. Structural modeling captures the static features of a system.
b. Structural model represents the framework for the system and
this framework is the place where all other components exist.
c. Hence, the class diagram, component diagram and deployment
diagrams are part of structural modeling.
d. They all represent the elements and the mechanism to assemble
them.
e. The structural model never describes the dynamic behavior of the
system.
2. Behavioral Modeling :
a. Behavioral model describes the interaction in the system.
b. It represents the interaction among the structural diagrams.
c. Behavioral modeling shows the dynamic nature of the system.
d. It consists of Activity diagrams, Interaction diagrams, Use case
diagrams.
3. Architectural Modeling :
a. Architectural model represents the overall framework of the system.
b. It contains both structural and behavioral elements of the system.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Architectural modeling :
1. Architectural modeling represents the overall framework of the system.
2. It contains both structural and behavioral elements of the system.
3. Architectural modeling can be defined as the blueprint of the entire
system.
Diagrams used in architectural modeling :
1. The two types of diagrams that give descriptions of the physical
information about a system are deployment diagrams and component
diagrams.
2. Deployment diagrams show the physical relationship between hardware
and software in a system.
3. Component diagrams show the software components of a system and
their relationships.
4. These relationships are called dependencies.
A. Component diagrams :
1. The component diagrams are mainly used to model the static
implementation view of a system.
2. They represent a high-level packaged view of the code.
3. They can be used to model executables, databases and adaptable systems.
4. Component diagrams mainly contain the following :
i. Components :
a. A component is a physical, replaceable part of a system that
packages implementation and provides the realization of a set
of interfaces.
b. A component is a physical manifestation of an object that has
a well-defined interface and a set of implementations for the
interface.
c. A complex system can be built using software components. It
enhances re-use in the system and facilitates system evolution.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Component
Component
Component dll
Component A
Realization
Interface Component A
Component A
<<interface>>
Name
Attributes
Operations
Interface name
Fig. 2.2.4. Representation of interfaces.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Node1
Communication
path
Node2
Answer
1. The phrase class is use to refer to a group of similar things.
2. A class describes a group of objects with similar properties, common
behavior, common relationships to other objects, and common semantics.
3. Objects in a class have the same attributes and behavior pattern.
4. Most objects derive their individuality from differences in their attribute
values and relationships to other objects.
5. The objects in a class share a common semantic purpose, above and
beyond the requirement of common attributes and behavior.
6. Each object “knows” its class.
7. Object-oriented programming languages can determine an object’s class
at run time.
8. An object’s class is an implicit property of the object.
Answer
Relationships : A model is not complete unless the relationships between
elements are described properly. The Relationship gives a proper meaning to
a UML model. Following are the different types of relationships used in
UML.
1. Dependency Notation :
a. Dependency describes the dependent elements and the direction of
dependency.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Generalization and specialization : Generalization and specialization
represent a hierarchy of relationships between classes, where subclasses
inherit from super-classes.
1. Generalization :
i. In the generalization process, the common characteristics of classes
are combined to form a class in a higher level of hierarchy, i.e.,
subclasses are combined to form a generalized super-class.
ii. It represents an “is - a - kind - of” relationship. For example, “car is
a kind of land vehicle”, or “ship is a kind of water vehicle”.
2. Specialization :
i. Specialization is the reverse process of generalization. Here, the
distinguishing features of groups of objects are used form specialized
classes from existing classes.
ii. It can be said that the subclasses are the specialized versions of the
super-class.
The following figure shows an example of generalization and specialization.
Vehicle
Specialization
Generalization
Fig. 2.5.1.
Relation to inheritance :
1. Developers use the term generalization or inheritance to refer to the
same concept of reusing shared attributes and operations that you show
in a superclass and reuse in subclasses.
2. Generalization refers to the concept of generalizing from specifics (the
subclasses) to the generic (the superclass).
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
House
Roofs Roofs
Answer
1. A country has a capital city : It is an association relationship. A
capital city and a country are distinct things so generalization certainly
does not apply. You could argue that a capital city is a part of a country
and thus they are related by aggregation.
2. Files contain records : It is an aggregation relationship. The word
“contain” is a clue that the relationship may be aggregation. A record is
a part of a file. Some attributes and operations on files propagate to their
constituent records.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Questions-Answers
Answer
Class diagram :
1. Class diagram is a static diagram.
2. It represents the static view of an application.
3. Class diagram is used for visualizing, describing, and documenting
different aspects of a system and also for constructing executable code
of the software application.
4. Class diagram describes the attributes and operations of a class and also
the constraints imposed on the system.
5. The class diagrams are widely used in the modeling of object-oriented
systems because they are the only UML diagrams, which can be mapped
directly with object-oriented languages.
For example :
Party
location
* children
0..1 parent
Person Organization
Object diagram :
1. Object diagrams represent an instance of a class diagram.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
2. Object diagrams represent the static view of a system but this static
view is a snapshot of the system at a particular moment.
3. Object diagrams are used to render a set of objects and their relationships
as an instance.
For example :
Engineering : Organization
Location = ‘‘Banglore’’
Parent
Parent
Answer
For example :
1. A class is a way of grouping objects that share a number of characteristics:
attributes (like name, color, height, weight, etc.) and behavior (such as
ability to perform jumps, to run, to swim, etc.).
2. All objects in the class horse will have an attribute named height, for
example. That means that all object in that class have a height-the value
of the attribute height will be different for each instance of the class
(i.e., for each particular horse).
i. A program for laying out a newspaper : Classes that you would
expect in a program for newspaper layout include Page, Column, Line,
Headline, and Paragraph.
ii. A catalog store order entry system : For a catalog store order entry
system, classes include Customer, Order, Store, and Item.
Que 2.9. Give the general layout of a class diagram. Also prepare
a class diagram for the instance diagram shown in the Fig. 2.9.1.
Explain your multiplicity decisions. How does your diagram express
the fact that points are in sequence ?
(Polygon)
Next
(Point) Last First (Point)
– 10 10
– 10 – 10
Next
Fig. 2.9.1.
Answer
0..1 1 1
Polygon first Point next
last x : real
0..1 1 y : real 1
Fig. 2.9.2. General class diagram for polygon and points.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Mate
(Person) (Person)
a grandmother a grandfather
Child Child
Fig. 2.10.1.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
A. Difference :
S. No. Class diagram Instance diagram
1. A class diagram is a schema, An instance diagram describes
pattern, or template for describing how does a particular set of
many possible instances of data. object relates to each other.
2. A class diagram describes the An instance diagram describes
general case in modeling a object instances.
system.
3. A class diagram describes object An instance diagram is useful
classes. for documenting test cases,
especially scenarios, and is used
to show examples to help to
clarify a complex class diagram.
4. The OMT symbol for a class is a Figure below shows the OMT
rectangular box with class name represe ntation of instance
in boldface. A line is drawn diagram. The class name in
between the class name and parenthesis is at the top of the
attributes. object box in boldface and object
names are listed in normal font
Person
with their attributes.
(PERSON)
Saurabh
26
D. Class Diagram :
wife 0..1 Cousin
Mate * *
0..1
husband *
Sibling
Person
mother
*
father
1 1
child * * child
Answer
CheckoutEvent
* *
checkoutDate
dueDate
CheckoutType
dateReturned
1 * /lateCharge
finePerDay
Questions-Answers
Answer
Collaboration diagram :
1. A collaboration diagram, also known as a communication diagram, is an
illustration of the relationships and interactions among software objects
in the Unified Modeling Language (UML).
2. These diagrams can be used to portray the dynamic behavior of a
particular use case and define the role of each object.
3. Collaboration diagrams are created by first identifying the structural
elements required to carry out the functionality of an interaction.
Various terms used in collaboration diagram :
1. Objects : Objects are shown as rectangles with naming labels inside.
The naming label follows the convention of object name; class name.
Object
name
2. Actors : Actors are instances that invoke the interaction in the diagram.
Each actor has a name and a role, with one actor initiating the entire
use case.
3. Links : Links connect objects with actors and are depicted using a solid
line between two elements. Each link is an instance where messages
can be sent.
Link
4. Messages : Messages between objects are shown as a labeled arrow
placed near a link. These messages are communications between objects
that convey information about the activity and can include the sequence
number.
Polymorphism using collaboration diagram :
1. Fig. 2.12.1 uses a collaboration diagram to illustrate polymorphism in a
business scenario.
2. The diagram assumes that there are different ways of calculating an
employee’s pay.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
3. Full-time employees are paid a salary that depends only on his or her
grade; part-time staff are paid a salary that depends in a similar way on
grade, but must also take into account the number of hours worked;
temporary staff differ in that no deductions are made for the company
pension scheme, but the salary calculation is otherwise the same as for
a full-time employee.
4. An object-oriented system to calculate pay for these employees might
include a separate class for each type of employee, each able to perform
the appropriate pay calculation.
5. However, following the principle of polymorphism, the message signature
for all calculate pay operations is the same.
Fixed monthly
amount depends only
on employee grade
2a:=calculatePay()
:FullTimeEmployee
Variable monthly
amount depends on
1:=getTotal grade and hours
2b:=calculatePay()
Pay()
MonthlyPayPrint :PartTimeEmployee
6. Suppose one of the outputs from this system is a print-out showing the
total pay for the current month: to assemble the total, a message is sent
to each employee object, asking it to calculate its pay.
7. Since the message signature is the same in each case, the requesting
object (here called MonthlyPayPrint) need not know that the class of
each receiving object, still less how each calculation is carried out.
Answer
Polymorphism :
1. Polymorphism means having many forms.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Questions-Answers
Answer
Sequence diagram :
1. Sequence diagrams describe interactions among classes in terms of an
exchange of messages over time.
2. They’re also called event diagrams.
3. A sequence diagram is a good way to visualize and validate various
runtime scenarios.
4. In UML it is shown as a table that shows objects arranged along the X
axis and messages along the Y axis.
5. It has a global life line and the focus of control.
Various terms and symbols used in sequence diagram :
1. Class roles or Participants : Class roles describe the way an object
will behave in context.
Object
Fig. 2.14.1.
2. Activation or Execution Occurrence : Activation occurrence
represent the time an object needs to complete a task. When an object is
busy executing a process or waiting for a reply message, use a thin gray
rectangle placed vertically on its lifeline.
Activation
occurrence
Fig. 2.14.2.
3. Messages : Messages are arrows that represent communication between
objects. Use half-arrowed lines to represent asynchronous messages.
Asynchronous messages are sent from an object that will not wait for a
response from the receiver before continuing its tasks.
Asynchronous
message
Synchronous
message
Fig. 2.14.3.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
4. Lifelines : Lifelines are vertical dashed lines that indicate the object’s
presence over time.
Lifeline
Fig. 2.14.4
operate
recordEntry (signDuration)
(personID, doorID,
actualTime)
time
Fig. 2.14.7. Three parallel queues, each with its own priority.
Broadcast message :
1. A broadcast message treats every object in the system as a potential
target.
2. A copy of the message goes into the queue of every object in the
system.
3. An object may broadcast a message in response to some external
event that it detects.
4. For example, an object might detect a security compromise and
broadcast to all objects the need for a priority system shutdown.
5. Fig. 2.14.9 shows the UML for a broadcast message. Here, a start-
up sequencer is getting every object in the system that exists at
start-up time to load itself.
* : load ( )
<<broadcast>>
: StartUpSequencer : (Object)
Answer
Significance of sequence diagram :
i. Sequence diagrams are one of the important dynamic modeling
techniques in the UML.
ii. These diagrams are used by software developers and business
professionals to understand requirements for a new system or to
document an existing process.
i. Broadcast messages : Refer Q. 2.14, Page 2-17L, Unit-2.
ii. Callback mechanism :
1. Here the subscriber object registers an interest in some event via
an asynchronous message to the target object.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
registerNewEMailEvent
(urgencyThresh)
newEMailReceived
(highestUrgency)
time
open (time,
highestUrgency)
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Questions-Answers
Answer
i. Behavioral models describe the internal dynamic aspects of an information
system that supports the business processes in an organization.
ii. During analysis, behavioral models describe what the internal logic of
the processes is without specifying how the processes are to be
implemented.
iii. In the design and implementation phases, the detailed design of the
operations contained in the object is fully specified.
iv. There are two types of behavioral models. First, there are behavioral
models that are used to represent the underlying details of a business
process portrayed by a use case model. In UML, interaction diagrams
(sequence and communication) are used for this type of behavioral
model.
v. Second, there is a behavioral model that is used to represent the changes
that occur in the underlying data. UML uses behavioral state machines
for this.
vi. During the analysis phase, analysts use behavioral model to capture a
basic understanding of the dynamic aspects of the underlying business
process.
vii. Traditionally, behavioral models have been used primarily during the
design phase where analysts refine the behavioral models to include
implementation details.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Que 2.17. Write a short note on use case diagram and time diagram
with suitable diagram and their utility in system design.
Answer
Vending machine
Buy
beverage
Customer
Perform
scheduled
maintenance
Technician
Make
repairs
Load items
Clerk
Time diagram :
1. Timing diagram is used to show interactions when a primary purpose of
the diagram is about time.
2. It focuses on conditions changing within and among lifelines along a
linear time axis.
3. Timing diagram is a special form of a sequence diagram.
Utility of time diagram in system design :
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. It depicts a graphical representation of states of a lifeline per unit time.
For example :
State {Duration constraint
d ..... 3d}
Fig. 2.17.2.
Answer
1. Package diagrams are structural diagrams used to show the organization
and arrangement of various model elements in the form of packages.
2. A package is a group of elements (classes, associations, generalizations,
and lesser packages) with a common theme.
3. A package partitions a model, making it easier to understand and
manage. Large applications may require several tiers of packages.
4. Packages form a tree with increasing abstraction toward the root, which
is the application, the top-level package.
5. As Fig. 2.18.1 shows, the notation for a package is a box with a tab. The
purpose of the tab is to suggest the enclosed contents, like a tabbed
folder.
PackageName
Que 2.19. Write short notes on use case diagram with suitable
diagram and their utility in system design.
AKTU 2014-15, Marks 05
Answer
Use case diagrams :
1. Use cases describe how a system interacts with external user of a system
(i.e., actor).
2. Each use case represents a piece of functionality that a system provides
to its users.
3. Use cases are helpful for capturing informal requirements.
4. Use case consists of actors.
5. An actor is an object or set of objects that communicates directly with
the system but that is not part of the system.
6. The various interactions of actors with a system are quantized into use
cases.
7. A use case is a coherent piece of functionality that a system can provide
by interacting with actors.
8. For example, a customer actor can buy a beverage from a vending
machine. The customer inserts money into the machine, makes a
selection, and ultimately receives a beverage. Similarly, a repair
technician can perform scheduled maintenance on a vending machine.
9. Fig. 2.19.1 summarizes several use cases for a vending machine.
Buy a beverage : The vending machine delivers a beverage after a
customer selects and pays for it.
Perform scheduled maintenance : A repair technician performs
the periodic service on the vending machine necessary to keep it in
good working condition.
Make repairs : A repair technician performs the unexpected service
on the vending machine necessary to repair a problem in its operation.
Load items : A stock clerk adds items into the vending machine to
replenish its stock of beverages.
Answer
1. An activity diagram is a flowchart that shows activities performed by a
system.
2. The two special states shown in an activity diagram are the Initial State
(Start Point) and Final State (End Point).
3. Initial State or Start Point : A small filled circle followed by an arrow
represents the initial action state or the start point for any activity diagram.
Start Point/Initial State
4. Final State or End Point : An arrow pointing to a filled circle nested
inside another circle represents the final action state.
Ent Point Symbol
For example :
data entry
generate
processing
output
Answer
State machine : A state machine diagram models the behaviour of a single
object, specifying the sequence of events that an object goes through during
its lifetime in response to events.
Downloaded by KS ([email protected])
Diagram :
calledPhoneHangsUp
Warning Timeout Recorded Message
onHook
timeout
Initial Pseudo State digit(n) invalidNumber
timeout
calledPhoneAnswers calledPhoneHangsUp
lOMoARcPSD|22022671
numberBusy trunkBusy
Downloaded by KS ([email protected])
Fig. 2.21.1. State machine diagram for answering a telephone call.
2–28 L (CS/IT-Sem-5)
lOMoARcPSD|22022671
Que 2.22. What do you mean by event ? What are the types of
Answer
1. An event is something that happens at a point in time, such as user
presses right mouse button. An event is a one-way transmission of
information from one object to another. An event conveys information
from one object to another.
2. An event has no duratio n. By de finition, an e ve nt happe ns
instantaneously with regard to time scale of an application.
3. Following are three most common events :
A. Signal event :
1. A signal event is the event of sending or receiving a signal.
2. A signal is a one-way transmission of information from one
object to another.
3. A signal is a message between objects while a signal event is
an occurrence in time.
For example, TrainDeparture has attributes train, trainNumber, city,
and date. The UML notation is the keyword signal in guillements (<< >>)
above the signal class name in the top section of a box. The bottom section
lists the signal attributes.
<<signal>>
TrainDeparture
train
trainNumber
city
date
Fig. 2.22.1.
B. Time event :
1. A time event is an event caused by the occurrence of an
absolute time or the elapse of a time interval.
2. For example, Fig. 2.22.2 shows, the UML notation for an
abso lute time is the ke ywo rd when fo llo we d by a
parenthesized expression involving time. The notation for
time interval is the keyword after followed by a parenthesized
expression that evaluates to a time duration.
Fig. 2.22.2.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
C. Change event :
1. A change event is an event caused by the satisfaction of a
boolean expression.
2. The boolean expression is continually tested and whenever
the expression changes from false to true, the event occurs.
3. For example, the UML notation for a change event is the
keyword when followed by a parenthesized boolen expression.
Fig. 2.22.3 shows examples of change events.
Fig. 2.22.3.
Que 2.23. Explain use case with example. How are the diagrams
Answer
Use case diagrams :
1. Use cases describe how a system interacts with external user of a system
(i.e., actor).
2. Each use case represents a piece of functionality that a system provides
to its users.
3. Use cases are helpful for capturing informal requirements.
4. Use case consists of actors.
5. An actor is an object or set of objects that communicates directly with
the system but that is not part of the system.
6. The various interactions of actors with a system are quantized into use
cases.
7. A use case is a coherent piece of functionality that a system can provide
by interacting with actors.
8. For example, a customer actor can buy a beverage from a vending
machine. The customer inserts money into the machine, makes a
selection, and ultimately receives a beverage. Similarly, a repair
technician can perform scheduled maintenance on a vending machine.
9. Fig. 2.23.1 summarizes various use cases for a vending machine.
Buy a beverage : The vending machine delivers a beverage
after a customer selects and pays for it.
Perform scheduled maintenance : A repair technician
performs the periodic service on the vending machine necessary
to keep it in good working condition.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Questions-Answers
Answer
1. Component diagrams :
1. The component diagrams are mainly used to model the static
implementation view of a system.
2. They represent a high-level packaged view of the code.
3. They can be used to model executables, databases and adaptable
systems.
4. Component diagrams mainly contain the following :
i. Components :
a. A component is a physical, replaceable part of a system that
packages implementation and provides the realization of a set
of interfaces.by KS ([email protected])
Downloaded
lOMoARcPSD|22022671
Component
Component
Component dll
Component A
Realization
Interface Component A
Component A
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
<<interface>>
Name
Attributes
Operations
Interface name
Fig. 2.24.4. Representation of interfaces.
Answer
Deployment diagram :
1. They display the configuration of run-time processing elements and the
software components, processes and objects.
2. The deployment diagram contains nodes and connection. A node is a
piece of hardware in the system.
3. A connection depicts the communication path used by the hardware
Fig. 2.25.1.
Node1
Communication
path
Node2
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
3
UNIT
Object Oriented
Analysis
CONTENTS
Part-1 : Object Oriented Analysis, ....................... 3–2L to 3–11L
Object Oriented Design, Object
Design, Combining Three Models,
Designing Algorithm, Design
Optimization, Implementation of
Control, Adjustment of Inheritance,
Object Representation, Physical
Packaging, Documenting
Design Consideration
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
PART-1
Object Oriented Analysis, Object Oriented Design, Object
Design, Combining Three Models, Designing Algorithm, Design
Optimization, Implementation of Control, Adjustment of
Inheritance, Object Representation, Physical Packaging,
Documenting Design Consideration.
Questions-Answers
Que 3.1. Write short note on object oriented analysis and object
oriented design.
Answer
Object oriented analysis :
1. Object-Oriented Analysis (OOA) is the procedure of identifying software
engineering requirements and developing software specifications in
terms of a software system's object model, which comprises of interacting
objects.
2. The primary tasks in object-oriented analysis (OOA) are :
a. Identifying objects
b. Organizing the objects by creating object model diagram.
c. Defining the internals of the objects, or object attributes.
d. Defining the behavior of the objects, i.e., object actions.
e. Describing how the objects interact.
3. The common models used in OOA are use cases and object models.
Object-Oriented Design :
1. Object-Oriented Design (OOD) involves implementation of the
conceptual model produced during object-oriented analysis.
2. In OOD, concepts in the analysis model, which are technology
independent, are mapped onto implementing classes, constraints are
identified and interfaces are designed, resulting in a model for the solution
domain, i.e., a detailed description of how the system is to be built on
concrete technologies.
3. The implementation details include :
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. After the hierarchy of subsystems has been developed, the objects in
the system are identified and their details are designed.
2. Here, the designer details out the strategy chosen during the system
design.
3. The emphasis shifts from application domain concepts toward computer
concepts.
4. The objects identified during analysis are etched out for implementation
with an aim to minimize execution time, memory consumption, and
overall cost.
5. Object design includes the following phases :
a. Object identification
b. Object representation, i.e., construction of design models
c. Classification of operations
d. Algorithm design
e. Design of relationships
f. Implementation of control for external interactions
g. Package classes and associations into modules
Answer
1. The operations in the objects are defined using algorithms.
2. An algorithm is a stepwise procedure that solves the problem laid
down in an operation. Algorithms focus on how it is to be done.
3. There may be more than one algorithm corresponding to a given
operation.
4. Once the alternative algorithms are identified, the optimal algorithm
is selected for the given problem domain.
5. The metrics for choosing the optimal algorithm are :
a. Computational Complexity : Complexity determines the efficiency
of an algorithm in terms of computation time and memory requirements.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Refer Q. 1.13, Page 1-12L, Unit-1.
Que 3.5. What are the three models in OMT ? How is the object
oriented analysis and design attached with OMT ? Explain with an
example. AKTU 2013-14, Marks 10
Answer
Following are the three models in OMT :
1. Object model :
a. Object model enco mpasses the principle s of abstraction,
encapsulation, modularity, hierarchy, typing, concurrency and
persistence.
b. Object model emphasizes on the object and class.
c. Main concepts related with object model are classes and their
association with attributes.
d. Predefined relationships in object model are aggregation and
generalization (multiple inheritance).
2. Dynamic model :
a. Dynamic model involves states, events and state diagram (transition
diagram) on the model.
b. Main concepts related with dynamic model are states, transition
between states and events to trigger the transitions.
c. Predefined relationships in object model are aggregation
(concurrency) and generalization.
3. Functional model :
a. Functional Model focuses on the how data is flowing, where data is
stored and different processes.
b. Main concepts involved in functional model are data, data flow,
data store, process and actors.
c. Functional model describes the whole processes and actions with
the help of data flow diagram (DFD).
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. The functional model shows what “has to be done” by a system. The
leaf process are the operation on objects.
2. The object model shows the “doers” the objects. Each process is
implemented by a method on some object.
3. The dynamic model shows the sequences in which the operations are
performed. Each sequence is implemented as a sequence, loop or
alteration of statements within some method.
4. The processes in the functional model correspond to operations in the
object model.
5. Actors are explicit objects in the object models. Data flows to or from
actors represent operations on or by the objects.
6. Because actors are self-motivated objects, the functional model is not
sufficient to indicate when they act. The dynamic model for an actor
object specifies when it acts.
Relationship between OOA and OOD :
1. When object orientation is used in analysis as well as design, the
boundary between OOA and OOD is blurred. This is particularly true
in methods that combine analysis and design.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
2. One reason for this blurring is the similarity of basic constructs (i.e.,
objects and classes) that are used in OOA and OOD.
Problem
Domain
Representation Design
Solution Domain
Representation
Answer
Optimization of design :
1. Design optimization is an engineering design methodology using a
mathematical formulation of a design problem to support selection of
the optimal design among many alternatives.
2. Design optimization involves the following stages :
a. Variables : Describe the design alternatives.
b. Objective : Elected functional combination of variables (to be maximized
or minimized).
c. Constraints : Combination of variables expressed as equalities or
inequalities that must be satisfied for any acceptable design alternative.
d. Feasibility : Values for set of variables that satisfies all constraints and
minimizes/maximizes objective.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Employs Hasskill
Company Person Skill
1 * * *
Fig. 3.7.1.
Answer
1. The object designer may incorporate refinements in the strategy of
the state-chart model. In system design, a basic strategy for realizing
the dynamic model is made. During object design, this strategy is aptly
embellished for appropriate implementation.
2. The approaches for implementation of the dynamic model are :
a. Represent state as a location within a program :
i. This is the traditional procedure-driven approach whereby
the location of control defines the program state.
ii. A finite state machine can be implemented as a program.
iii. A transition forms an input statement, the main control path
forms the sequence of instructions, the branches form the
conditions, and the backward paths form the loops or
iterations.
b. State machine engine :
i. This approach directly represents a state machine through a
state machine engine class.
ii. This class executes the state machine through a set of
transitions and actions provided by the application.
c. Control as concurrent tasks :
i. In this approach, an object is implemented as a task in the
programming language or the operating system.
ii. Here, an event is implemented as an inter-task call.
iii. It preserves inherent concurrency of real objects.
Answer
1. Once the classes are identified, they need to be represented using
object modeling techniques.
2. This stage essentially involves constructing UML diagrams.
3. There are two types of design models that need to be produced :
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Physical packaging :
1. A component is a physical and replaceable part of the system that
conforms and provides the realization of a set of interfaces.
2. It represents the physical packaging of elements like classes and
interfaces.
3. A package is an organized group of elements. A package may contain
structural things like classes, components, and other packages in it.
4. For example, a package is represented by a tabbed folder.
5. A package is generally drawn with only its name. However, it may have
additional details about the contents of the package.
Customer
+ Personal_details
+ Account_details
+ Loan_details
Answer
The different aspects of packaging are :
1. Hiding internal information from outside view :
a. It allows a class to be viewed as a "black box" and permits class
implementation to be changed without requiring any clients of the
class to modify code.
2. Coherence of elements :
a. An element, such as a class, an operation, or a module, is coherent
if it is organized on a consistent plan and all its parts are intrinsically
related so that they serve a common goal.
3. Construction of physical modules : The following guidelines help
while constructing physical modules :
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Documentation :
1. Documentation is a software development process that records the
procedure of making the software.
2. The design decisions need to be documented for any non-trivial software
system for transmitting the design to others.
3. Though a secondary product, a good documentation is indispensable,
particularly in the following areas :
a. In designing software that is being developed by a number of
developers.
b. In iterative software development strategies.
c. In developing subsequent versions of a software project.
d. For evaluating a software.
e. For finding conditions and areas of testing.
f. For maintenance of the software.
Various Consideration of documentation designing :
1. It is a roadmap :
a. It allows standardization, and it helps to identify the stages that can
be improved.
b. Process documentation also facilitates the training of new
employees.
2. It is everyone’s task :
a. The members of an area or project are responsible for documenting
their processes.
b. Every employee knows their own functioning, their strength, and
their weakness, so they are the ones better indicates to document
their processes.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Multiple inheritance :
1. Multiple inheritance is a feature of object-oriented computer
programming languages in which an object or class can inherit
characteristics and features from more than one parent object or parent
class.
2. When one class extends more than one classes then this is called multiple
inheritance.
For example : Class C extends class A and B then this type of inheritance
is known as multiple inheritance.
A B
Fig. 3.13.1.
Answer
Documentation design considerations : Refer Q. 3.12, Page 3-9L, Unit-3.
Following kinds of adjustments can be used to increase the chance
of inheritance :
1. Some operations may have fewer arguments than others. The missing
arguments can be added but ignored. For example, a draw operation on
a monochromatic display does not need a color parameter, but the
parameter can be accepted and ignored for consistency with color
displays.
2. Similar attributes in different classes may have different names. Give
the attributes the same name and move them to the common ancestor
class. Then operations that access the attributes will match better.
3. Some operations may have fewer arguments because they are special
cases of more general arguments. Implement the special operations by
calling the general operation with appropriate parameter values.
4. Opportunities to use inheritance are not always recognized during the
analysis phase of development, so it is worthwhile to reexamine the
object model looking for commonality between classes.
PART-2
Structured Analysis and Structured Design(SA/SD), Jackson
Structured Development(JSD), Mapping Object Oriented
Concepts Using Non-Object Oriented Language, Translating
Classes Into Data Structures, Passing Arguments to Method,
Implementing Inheritance, Association Encapsulation.
Questions-Answers
OR
Explain structured analysis and structured design (SA/SD) with
example. AKTU 2015-16, Marks 10
Answer
Structured analysis and structure design :
1. Structured Analysis and Structured Design (SA/SD) is diagrammatic
notation which is design to help people understand the system.
2. The basic goal of SA/SD is to improve quality and reduce the risk of
system failure.
3. It establishes concrete management specification and documentation.
4. It focuses on solidity, pliability and maintainability of system.
5. The approach of SA/SD is based on the Data Flow Diagram.
6. It is easy to understand SA/SD but it focuses on well defined system
boundary whereas JSD approach is too complex and does not have any
graphical representation.
7. SA/SD is combined known as SAD and it mainly focuses on following
three points :
a. System
b. Process
c. Technology
8. SA/SD involves two phases :
a. Analysis Phase : It uses Data Flow Diagram, Data Dictionary,
State Transition diagram and ER diagram.
b. Design Phase : It uses Structure Chart and Pseudo Code.
9. For example :
i. During structured design, data flow diagram processes are grouped
into tasks and allocated to operating system processes and CPUs.
ii. Data flow diagram processes are converted into programming
language functions, and a structure chart is created showing the
procedure call tree.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Answer
1. Jackson System Development (JSD) is a method of system development
that covers the software life cycle either directly or by providing a
framework into which more specialized techniques can fit.
2. JSD can start from the stage in a project when there is only a general
statement of requirements.
3. Following are the phases of JSD :
a. Modeling phase : In the modeling phase, the designer creates a
collection of entity structure diagrams and identifies the entities in
the system, the actions they perform, the attributes of the actions
and time ordering of the actions in the life of the entities.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Implementing an object-oriented concept in a non-object oriented language
requires the following steps :
1. Translate classes into data structures :
i. Each class is implemented as a single contiguous block of attributes.
Each attribute contains variable. Now an object has state and identity
and is subject to side effects.
ii. A variable that identifies an object must therefore be implemented
as a sharable reference.
2. Pass arguments to methods :
i. Every method has at least one argument. In a non-object-oriented
language, the argument must be made explicit.
ii. Methods can contain additional objects as arguments. In passing an
object as an argument to a method, a reference to the object must
be passed if the value of the object can be updated within the
method.
3. Allocate storage for objects :
i. Objects can be allocated statically, dynamically or on a stack.
ii. Most temporary and intermediate objects are implemented as stack-
based variables.
iii. Dynamically allocated objects are used when there number is not
known at compile time.
iv. A general object can be implemented as a data structure allocated
on request at run time from a heap.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
i. It is easy to implement an object-oriented design with an object-oriented
language since language constructs are similar to design constructs.
ii. The following steps are required to implement an object oriented design
in an object-oriented language :
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
1. Class definitions :
i. The first step in implementing an object-oriented design is to declare
object classes. Each attribute and operation in an object diagram
must be declared as part of its corresponding class.
ii. Assign data types to attributes. Declare attributes and operations
as either public or private.
2. Creating objects :
i. Object-oriented languages create new objects in following two ways :
a. Class operation applied to a class object creates a new object of
the class.
b. Using special operations that create new objects.
ii. When a new object is created, the language allocates storage for its
attribute values and assigns it a unique object ID.
3. Calling operations :
i. In most object-oriented languages, each operation has at least one
implicit argument, the target object, indicated with a special syntax.
ii. Operations may or may not have additional arguments.
4. Using Inheritance :
i. To implement inheritance object-oriented languages use different
mechanisms.
ii. There are three independent dimensions for classifying inheritance
mechanisms :
a. Static or dynamic
b. Implicit or explicit
c. Per object or per group.
iii. Many of the popular languages are static, implicit and per group.
5. Implementing associations :
i. There are two approaches to implement associations : buried
pointers and distinct association objects.
ii. If the language does not explicitly support association objects then
buried pointers are easy to implement.
iii. An association can also be implemented as a distinct container
object.
Answer
1. There are different ways in which parameter data can be passed into
and out of methods and functions.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
2. Let us assume that a function B() is called from another function A(). In
this case A is called the “caller function” and B is called the “called
function or callee function”.
3. The arguments which A sends to B are called actual arguments and the
parameters of B are called formal arguments.
4. Following are the types of parameters :
a. Formal parameter : A variable and its type as they appear in the
prototype of the function or method.
Syntax : function_name(datatype variable_name) :
b. Actual parameter : The variable or expression corresponding to a
formal parameter that appears in the function or method call in the
calling environment.
Syntax : func_name(variable name(s));
Answer
1. Inheritance is the sharing of attributes and operations among classes
based on a hierarchical relationship.
2. Object-oriented languages provide strong support for implementation
of inheritance.
3. Inheritance has become synonymous with code reuse within the object-
oriented programming community.
4. After modeling a system, the developer looks at the resulting classes
and tries to group similar classes together and reuse common code.
5. Often code is available from past work (such as a class library) which the
developer can reuse and modify to get the precise desired behavior.
PART-3
Object Oriented Programming, Reusability, Extensibility,
Robustness, Programming in the Large, Procedural v/s OOP,
Object Oriented Language Feature, Abstraction and Encapsulation.
Questions-Answers
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Features of object-oriented language are :
1. Encapsulation :
i. Encapsulation means that data are encapsulated inside an inviolable
shell along with the methods required to use it.
ii. The only way to reach the data is through these particular methods
(see Fig. 3.22.1).
iii. It is the mechanism that binds together code and the data it
manipulates.
iv. This concept is also used to hide the internal representation, or
state, of an object from the outside.
Object 1 Object 2
Message C
Method 2
Method 1
Data Data
Method 1
Method 5
Method 3
Method 6
Message B
Message A
Fig. 3.22.1. Message passing between objects with encapsulation,
activating methods that can use or modify the data
within their object.
2. Polymorphism :
i. Polymorphism means having many forms.
ii. Polymorphism is the ability of a message to be displayed in more
than one form.
iii. It plays an important role in allowing objects having different
internal structure to share the same external interface.
3. Inheritance :
i. Inheritance is the ability to create classes that share the attributes
and methods of existing classes, but with more specific features.
ii. Inheritance is mainly used for code reusability.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Difference :
S. No. C++ Java
Answer
i. Reusability :
1. Reusability is a segment of source code that can be used again to add
new functionalities with slight or no modification.
2. Reusable software reduces design, coding and testing cost. Also, reducing
the amount of code simplifier understanding. In object-oriented
languages the possibility of code reuse is greatly enhanced.
3. There are two kind of reuse :
i. Sharing of newly-written code within a project.
ii. Reuse of previously-written code on new project.
4. Rules for reusability : Following rules must be kept in mind :
i. Keep methods coherent.
ii. Keep methods small.
iii. Keep method consistent.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
CONTENTS
Part-1 : C++ Basics, Overview, ............................. 4–2L to 4–10L
Program Structure, Namespace,
Identifiers, Variables,
Constants, Enum, Operators,
Typecasting, Control Structures
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
PART-1
C++ Basics, Overview, Program Structure, Namespace, Identifiers,
Variables, Constants, Enum, Operators, Typecasting,
Control Structures.
Questions-Answers
Answer
1. C++ is an object-oriented programming language developed by Bjarne
Stroustrup.
2. C++ is a cross-platform language that can be used to create high-
performance applications.
2. C++ is a versatile language for handling very large programs.
3. It is suitable for variety of programming task including development of
editors, compilers, and different complex real-life application systems.
Applications of C++ :
1. Since C++ allows us to create hierarchy-related objects, we can build
special object oriented libraries which can be used later by many
programmers.
2. While C++ is able to map the real-world problem properly, the C part of
C++ gives the language the ability to get close to the machine-level
details.
3. C++ programs are easily maintainable and expandable. When a new
feature needs to be implemented, it is very easy to add to the existing
structure of an object.
Answer
1. Fig. 4.2.1 shows the structure of C++ program that contain four sections.
2. The class declarations are placed in a header file and the definitions of
member functions go into another file.
3. This approach enables the programmer to separate the abstract
specification of the interface (class definition) from the implementation
details (member functions
Downloaded by KSdefinition).
([email protected])
lOMoARcPSD|22022671
4. The main program that uses the class is placed in a third file which
“includes” the previous two files as well as any other files required.
Include files
Class declaration
Member functions definitions
Main function program
Answer
A. Namespace :
1. Namespace defines a scope for the identifiers that are used in a program.
2. For using the identifiers defined in the namespace scope we must include
the using directive :
using namespace std;
3. Here, std is the namespace where standard class libraries are defined.
4. This directive will bring all the identifiers defined in std to the current
global scope.
B. Identifiers :
1. Identifiers refer to the names of variables, functions, arrays, classes,
etc., which are created by the programmer.
2. They are the fundamental requirement of any language.
3. Each language has its own rules for naming these identifiers. Following
are the rules for C++ :
a. Only alphabetic characters, digits and underscores are permitted.
b. The name cannot start with a digit.
c. Uppercase and lowercase letters are distinct.
d. A declared keyword cannot be used as a variable name.
C. Constants :
1. Constants refer to fixed values that do not change during the execution
of a program.
2. They include integers, characters, floating point numbers and strings.
3. Literal constant do not have memory locations.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
4. Examples :
123 // decimal integer
12.34 // floating point integer
037 // octal integer
0X2 // hexadecimal integer
“C++” // string constant
‘A’ // character constant
L ‘ab’ // wide-character constant
D. Enumerated :
1. An enum specifier defines the set of all names that will be permissible
values of the type. These permissible values are called members.
2. The enum type days_of_week has seven members : Sun, Mon, Tue, and
so on, up to Sat.
3. Enumerated means that all the values are listed.
4. This is unlike the specification of an int, for example, which is given in
terms of a range of possible values.
5. In an enum you must give a specific name to every possible value.
E. Variables :
1. A variable is a symbolic name that can be given a variety of values.
2. Variables are stored in particular places in the computer’s memory.
3. When a variable is given a value, that value is actually placed in the
memory space occupied by the variable.
4. Most popular languages use the same general variable types, such as
integers, floating-point numbers, and characters.
Que 4.4. Write a C++ program to calculate the value of sin (x) and
cos (x).
Answer
#include<iostream>
#include<math.h>
using namespace std;
//calculate value of sin
void cal_sin(float n) {
float acc = 0.0001, denominator, sinx, sinval;
n = n * (3.142 / 180.0); //convert in radian
float temp = n;
sinx = n;
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
sinval = sin(n);
int i = 1;
do {
denominator = 2 * i * (2 * i + 1);
temp = -temp * n * n / denominator;
sinx = sinx + temp;
i = i + 1;
} while (acc <= fabs(sinval - sinx));
cout<<sinx;
}
//calculate value of cos
void cal_cos(float n) {
float acc = 0.0001, temp, denominator, cosx, cosval;
n = n * (3.142 / 180.0); //convert in radiam
temp = 1;
cosx = temp;
cosval = cos(n);
int i = 1;
do {
denominator = 2 * i * (2 * i - 1);
temp = -temp * n * n / denominator;
cosx = cosx + temp;
i = i + 1;
} while (acc <= fabs(cosval - cosx));
cout<< cosx;
}
int main() {
float n = 30;
cout<<“value of Sin is : ”; cal_sin(n);
cout<<“\n”;
n=60;
cout<<“value of Cos is : ”;
cal_cos(n);
return 0;
}
Que 4.5. What are the different types of operators used in C++ ?
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. Memory Management Operators :
a. C++ defines two unary operators new and delete that perform the task
of allocating and freeing the memory in a easier way.
b. Since these operators manipulate memory on the free store, they are
also known as free store operators.
c. The new operator can be used to create objects of any type. It takes the
following general form :
Answer
Typecasting :
1. Converting an expression of a given type into another type is known as
typecasting.
2. Following Downloaded
are the types
byofKS
typecasting :
([email protected])
lOMoARcPSD|22022671
a. Implicit conversion :
i. Implicit conversions do not require any operator.
ii. They are automatically performed when a value is copied to a compatible
type.
iii. For example :
short a = 2000;
int b;
b = a;
b. Explicit conversion :
i. Many conversions, especially those that imply a different interpretation
of the value, require an explicit conversion.
ii. For example :
short a = 2000;
int b;
b = (int) a; // C like cast notation
b = int (a); // functional notation
c. Dynamic cast :
i. dynamic_cast can be used only with pointers and references to objects.
ii. Its purpose is to ensure that the result of the type conversion is a valid
complete object of the requested class.
d. Static cast :
i. static_cast can perform conversions between pointers to related classes,
not only from the derived class to its base, but also from a base class to
its derived.
e. reinterpret_cast :
i. reinterpret_cast converts any pointer type to any other pointer type,
even of unrelated classes.
ii. The operation result is a simple binary copy of the value from one
pointer to the other.
f. const_cast : This type of casting manipulates the constness of an object,
either to be set or to be removed.
g. typeid :
i. typeid allows to check the type of an expression :
typeid (expression)
ii. This operator returns a reference to a constant object of type type_info
that is defined in the standard header file <typeinfo>.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. The if statement : The if statement is implemented in two forms :
a. Simple if statement
b. if...else statement
2. The switch statement :
a. This is a multiple-branching statement where, based on a condition, the
control is transferred to one of the many possible points.
b. This is implemented as follows :
switch (expression)
{
case1 :
{
action1;
}
case2 :
{
action2;
}
case3 :
{
action3;
}
default :
{
action4;
}
}
action5;
3. The do-while statement :
a. The do-while is an exit-controlled loop. Based on a condition, the control
is transferred back to a particular point in the program.
b. The syntax is as follows :
do
{
action;
}
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
#include <iostream>
using namespace std;
int main()
{
char line[35];
int vowels;
vowels = 0;
cout<< “Enter a line of string: ”;
cin.getline(line, 35);
for(int i = 0; line[i]!=‘\0’; ++i)
{
if(line[i]==‘a’ || line[i]==‘e’ || line[i]==‘i’ ||
line[i]==‘o’ || line[i]==‘u’ || line[i]==‘A’ ||
line[i]==‘E’ || line[i]==‘I’ || line[i]==‘O’ ||
line[i]==‘U’)
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
{
++vowels;
}
}
cout<< “Vowels: ” <<vowels<<endl;
return 0;
}
Answer
PART-2
C++ Function, Simple Function, Call and Return by Reference,
Inline Function Macro vs Inline Functions, Overloading of
Functions, Default Arguments, Friend Functions, Virtual Function.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Questions-Answers
Answer
1. The main() returns a value of type int to the operating system.
2. C++ explicitly defines main() as matching one of the following
prototypes :
int main();
int main(int argc, char * argv[]);
3. The functions that have a return value should use the return statement
for termination.
4. Hence the main() function in C++ is defined as follows :
int main()
{
.......
.......
return 0;
}
5. Since the return type of functions is int by default, the keyword int in
the main() header is optional.
6. Most C++ compilers will generate an error or warning if there is no
return statement.
Answer
1. Call by reference :
a. Provision of the reference variables in C++ permits us to pass parameters
to the functions by reference.
b. When we pass arguments by reference, the ‘formal’ arguments in the
called function become aliases to the ‘actual’ arguments in the calling
function.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
c. This means that when the function is working with its own arguments,
it is actually working on the original data.
d. For example, consider the following function :
void swap(int &a, int &b) // a and b are reference variables
{
int t = a; // Dynamic initialization
a = b;
b = t;
}
Now, if m and n are two integer variables, then the function call
swap(m, n);
will exchange the values of m and n using their aliases (reference
variables) a and b.
2. Return by reference :
a. A function can also return a reference.
b. For example, consider the following function :
int & max(int &x, int &y)
{
if (x > y)
return x;
else
return y;
}
c. Since the return type of max() is int &, the function returns reference to
x or y (and not the values).
d. Then a function call such as max(a, b) will yield a reference to either a or
b depending on their values.
e. This means that this function call can appear on the left-hand side of an
assignment statement.
f. This means the statement
max(a, b) = – 1;
is legal and assigns – 1 to a if it is larger, otherwise –1 to b.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Answer
1. Inline function is a function that is expanded in line when it is called.
2. When the inline function is called whole code of the inline function gets
inserted or substituted at the point of inline function call.
3. This substitution is performed by the C++ compiler at compile time.
Inline function may increase efficiency if it is small.
4. The syntax for defining the function inline is :
inline return-type function-name(parameters)
{
// function code
}
Answer
#include<iostream>
using namespace std;
int main()
{
int val, num, sum = 0;
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
#include<iostream>
using namespace std;
class operation
{
int a, b, add, sub, mul;
float div;
public :
void get();
void sum();
void difference();
void product();
void division();
};
inline void operation :: get()
{
cout << “Enter first value:”;
cin >> a;
cout << “Enter second value:”;
cin >> b;
}
inline void operation :: sum()
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
{
add = a + b;
cout << “Addition of two numbers : ” << a + b << “\n”;
}
inline void operation :: difference()
{
sub = a – b;
cout << “Difference of two numbers :” << a – b << “\n”;
}
inline void operation :: product()
{
mul = a * b;
cout << “Product of two numbers: ” << a * b << “\n”;
}
inline void operation ::division()
{
div = a / b;
cout << “Division of two numbers: ”<< a / b << “\n” ;
}
int main()
{
cout << “Program using inline function\n”;
operation s;
s.get();
s.sum();
s.difference();
s.product();
s.division();
return 0;
}
Answer
A. Advantages :
1. Function call overhead doesn't occur.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
5. In C++, inline may be defined Whereas the macro is all the time
either inside the class or outside defined at the beginning of the
the class. program.
6. In C++, inside the class, the While the macro is specifically
short length functions are defined.
automatically made the inline
functions.
7. Inline is not as widely used as While the macro is widely used.
macros.
8. Inline is not used in competitive While the macro is very much
programming. used in co mpetitive
programming.
9. Inline function is terminated by While the macro is no t
the curly brace at the end. terminated by any symbol, it is
terminated by a new line.
Answer
1. C++ allows you to specify more than one definition for a function name
or an operator in the same scope, which is called function overloading.
2. An overloaded declaration is a declaration that is declared with the same
name as a previously declared declaration in the same scope, except that
both declarations have different arguments and different definition
(implementation).
3. When you call an overloaded function or operator, the compiler
determines the most appropriate definition to use, by comparing the
argument types you have used to call the function or operator with the
parameter types specified in the definitions.
4. The process of selecting the most appropriate overloaded function or
operator is called overload resolution.
Answer
#include<iostream>
using namespace std;
class Cal {
public:
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
#include<iostream>
using namespace std;
class Box
{
private:
int length;
public:
Box(): length(0) { }
friend int printLength(Box); //friend function
};
int printLength(Box b)
{
b.length += 10;
return b.length;
}
int main()
{
Box b;
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
#include<iostream>
using namespace std;
//function to find longest word
int word_length(string str) {
int len = str.length();
int temp = 0;
int newlen = 0;
for (int i = 0; i < len; i++) {
if (str[i] != ‘ ’)
newlen++;
else {
temp = max(temp, newlen);
newlen = 0;
}
}
return max(temp, newlen);
}
int main() {
string str = “Quantum Series is the best for clearing exam”;
cout << “maximum length of a word is : ” << word_length(str);
return 0;
}
Answer
A default argument is a value provided in a function declaration that is
automatically assigned by the compiler if the caller of the function doesn't
provide a value for the argument with a default value.
#include<iostream>
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. If a function is defined as a friend function in C++, then the protected
and private data of a class can be accessed using the function.
2. By using the keyword friend compiler knows the given function is a
friend function.
3. For accessing the data, the declaration of a friend function should be
done inside the body of a class starting with the keyword friend.
4. For example,
#include <iostream>
using namespace std;
class Box
{
private:
int length;
public:
Box(): length(0) { }
friend int printLength(Box); //friend function
};
Answer
Characteristics of friend function are :
1. The function is not in the scope of the class to which it has been declared
as a friend.
2. It cannot be called using the object as it is not in the scope of that class.
3. It can be invoked like a normal function without using the object.
4. It cannot access the member names directly and has to use an object
name and dot membership operator with the member name.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. A virtual function is a member function which is declared within a base
class and is redefined (Overridden) by a derived class.
2. When you refer to a derived class object using a pointer or a reference
to the base class, you can call a virtual function for that object and
execute the derived class’s version of the function.
3. Virtual functions ensure that the correct function is called for an object,
regardless of the type of reference (or pointer) used for function call.
4. They are mainly used to achieve Runtime polymorphism
5. Functions are declared with a virtual keyword in base class.
6. The resolving of function call is done at Run-time.
Que 4.26. What are the rules used for a virtual function ?
Answer
1. Virtual functions cannot be static and also cannot be a friend function of
another class.
2. Virtual functions should be accessed using pointer or reference of base
class type to achieve run time polymorphism.
3. The prototype of virtual functions should be same in base as well as
derived class.
4. They are always defined in base class and overridden in derived class. It
is not mandatory for derived class to override (or re-define the virtual
function), in that case base class version of function is used.
5. A class may have virtual destructor but it cannot have a virtual
constructor.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
CONTENTS
Part-1 : Objects and Classes, ................................... 5–2L to 5–6L
Basics of Object and Class
in C++, Private and
Public Members, Static
Data and Function Members
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
PART-1
Objects and Classes, Basics of Object and Class in C++, Private
and Public Members, Static Data and Function Members.
Questions-Answers
Answer
A. Object :
1. An Object is an instance of a Class. When a class is defined, no memory
is allocated but when it is instantiated (i.e. an object is created) memory
is allocated.
2. When a class is defined, only the specification for the object is defined;
no memory or storage is allocated. To use the data and access functions
defined in the class, you need to create objects.
B. Classes :
1. A class is a way to bind the data and its associated functions together. It
allows the data (and functions) to be hidden, if necessary, from external
use.
2. When defining a class, we are creating a new abstract data type that can
be treated like any other built-in data type.
3. The class declaration describes the type and scope of its members.
4. The class function definitions describe how the class functions are
implemented.
5. The general form of a class declaration is :
class class_name
{
private :
variable declarations;
function declarations;
public :
variable declarations;
function declarations;
};
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Que 5.2. Design a class using C++ to create a singly linked list.
Answer
#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
};
class list
{
private:
node *head, *tail;
public:
list()
{
head = NULL;
tail = NULL;
}
void createnode(int value)
{
node *temp = new node;
temp->data = value;
temp->next = NULL;
if(head == NULL)
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
{
head = temp;
tail = temp;
temp = NULL;
}
else
{
tail -> next = temp;
tail = temp;
}
}
};
int main()
{
list obj;
obj.createnode(25);
obj.createnode(50);
obj.createnode(90);
obj.createnode(40);
cout<<“\n--------------------------------------------------\n”;
cout<<“---------------Displaying All nodes---------------”;
cout<<“\n--------------------------------------------------\n”;
system(“pause”);
return 0;
}
Answer
1. A private member function can only be called by another function that
is a member of its class.
2. Even an object cannot invoke a private function using the dot operator.
3. Consider a class as defined below :
class sample
{
in m;
void read(void); // private member function
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
public :
void update(void);
void write(void);
};
4. If s1 is an object of sample, then
s1.read(); // won’t work; objects cannot access
// private members
is illegal.
5. However, the function read() can be called by the function update() to
update the value of m.
void sample : : update(void)
{
read(); // simple call; no object used
}
Answer
Answer
Static data :
1. Static data is data that does not change after being recorded. It is a fixed
data set.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
2. Experts contrast static data with dynamic data, where dynamic data
may change after it is recorded, and has to be continually updated.
Member function :
1. A member function of a class is a function that has its definition or its
prototype within the class definition like any other variable.
2. It operates on any object of the class of which it is a member, and has
access to all the members of a class for that object.
3. Member functions can be defined within the class definition or separately
using scope resolution operator.
4. Defining a member function within the class definition declares the
function inline, even if you do not use the inline specifier.
PART-2
Constructors and their Types, Destructors, Operators
Overloading, Type Conversion.
Questions-Answers
Answer
Constructor :
1. A constructor is a member function of a class which initializes objects of
a class.
2. In C++, Constructor is automatically called when object (instance of
class) create. It is special member function of the class.
A constructor is different from normal functions in following ways :
1. Constructor has same name as the class itself.
2. Constructors don't have return type.
3. A constructor is automatically called when an object is created.
4. If we do not specify a constructor, C++ compiler generates a default
constructor for us (expects no parameters and has an empty body).
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Different types of constructor are :
1. Default constructors :
a. Default constructor is the constructor which doesn’t take any
argument. It has no parameters.
b. Even if we do not define any constructor explicitly, the compiler
will automatically provide a default constructor implicitly.
2. Parameterized constructors :
a. It is possible to pass arguments to constructors. Typically, these
arguments help initialize an object when it is created.
b. To create a parameterized constructor, simply add parameters to it
the way you would to any other function.
c. When you define the constructor’s body, use the parameters to
initialize the object.
3. Copy constructor :
a. A copy constructor is a member function which initializes an object
using another object of the same class.
b. Whenever we define one or more non-default constructors (with
parameters) for a class, a default constructor (without parameters)
should also be explicitly defined as the compiler will not provide a
default constructor in this case.
c. However, it is not necessary but it’s considered to be the best practice
to always define a default constructor.
Answer
Destructor :
1. Destructor is a member function which destructs or deletes an object.
2. Following is the Syntax of destructor :
~constructor-name();
Properties of Destructor :
1. Destructor function is automatically invoked when the objects are
destroyed.
2. It cannot be declared static or const.
3. The destructor does not have arguments.
4. It has no return type not even void.
5. An object of a class with a Destructor cannot become a member of the
union.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
We call a destructor when :
1. A destructor function is called automatically when the object goes out of
scope :
a. The function ends
b. The program ends
c. A block containing local variables ends
d. A delete operator is called
2. Destructors are different from a normal member function :
a. Destructors have same name as the class preceded by a tilde (~).
b. Destructors don’t take any argument and don't return anything.
No, there can only one destructor in a class with classname preceded by ~, no
parameters and no return type.
Answer
1. Operator overloading is a compile-time polymorphism in which the
operator is overloaded to provide the special meaning to the user-defined
data type.
2. Operator overloading is used to overload or redefines most of the
operators available in C++.
3. It is used to perform the operation on the user-defined data type.
4. For example, C++ provides the ability to add the variables of the user-
defined data type that is applied to the built-in data types.
5. The advantage of Operators overloading is to perform different
operations on the same operand.
6. Syntax of Operator Overloading
return_type class_name : : operator op(argument_list)
{
// body of the function.
}
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
Rules for Operator Overloading :
1. Existing operators can only be overloaded, but the new operators cannot
be overloaded.
2. The overloaded operator contains at least one operand of the user-
defined data type.
3. We cannot use friend function to overload certain operators. However,
the member function can be used to overload those operators.
4. When unary operators are overloaded through a member function take
no explicit arguments, but, if they are overloaded by a friend function,
takes one argument.
5. When binary operators are overloaded through a member function
takes one explicit argument, and if they are overloaded through a friend
function takes two explicit arguments.
Answer
A type cast is basically a conversion from one type to another. There are two
types of type conversion :
1. Implicit Type Conversion (automatic type conversion) :
a. Done by the compiler on its own, without any external trigger from
the user.
b. Generally takes place when in an expression more than one data
type is present. In such condition type conversion (type promotion)
takes place to avoid lose of data.
c. All the data types of the variables are upgraded to the data type of
the variable with largest data type.
d. It is possible for implicit conversions to lose information, signs can
be lost (when signed is implicitly converted to unsigned), and
overflow can occur (when long is implicitly converted to float).
2. Explicit Type Conversion :
a. This process is also called type casting and it is user-defined. Here
the user can typecast the result to make it of a particular data type.
b. In C++, it can be done by two ways :
i. Converting by assignment :
a. This is done by explicitly defining the required type in
front of the expression in parenthesis. This can be also
considered as forceful casting.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
PART-3
Inheritance : Concept of Inheritance , Types of Inheritance : Single,
Multiple, Multilevel, Hierarchical , Hybrid, Protected
Members, Overriding, Virtual Base Class.
Questions-Answers
Answer
Inheritance :
1. The capability of a class to derive properties and characteristics from
another class is called Inheritance.
2. Inheritance is one of the most important features of Object Oriented
Programming.
3. The class that inherits properties from another class is called Sub class
or Derived class.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
4. The class whose properties are inherited by sub class is called Base Class
or Super class.
Modes of inheritance :
1. Public mode :
a. If we derive a sub class from a public base class.
b. Then the public member of the base class will become public in the
derived class and protected members of the base class will become
protected in derived class.
2. Protected mode :
a. If we derive a sub class from a Protected base class.
b. Then both public member and protected members of the base class
will become protected in derived class.
3. Private mode :
a. If we derive a sub class from a Private base class.
b. Then both public member and protected members of the base class
will become Private in derived class.
Answer
Different types of inheritance :
1. Single inheritance :
a. In single inheritance, a class is allowed to inherit from only one
class. i.e., one sub class is inherited by one base class only.
b. Following is the syntax :
class subclass_name : access_mode base_class
{
//body of subclass
};
2. Multiple inheritance :
a. Multiple inheritance is a feature of C++ where a class can inherit
from more than one classes. i.e one sub class is inherited from
more than one base classes.
b. Following is the syntax :
class subclass_name : access_mode base_class1, access_mode
base_class2, ....
{
//body of subclass
};
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. Protected access modifier is similar to private access modifier in the
sense that it can’t be accessed outside of it's class unless with the help of
friend class, the difference is that the class members declared as Protected
can be accessed by any subclass (derived class) of that class as well.
S. No. Public Protected
1. All the class me mbers Protected access modifier is
declared under public will be similar to that of private access
available to everyone. modifiers.
2. The data me mbers and The class member declared as
member functions declared Pro te cted are inaccessible
public can be accessed by outside the class but they can be
other classes too. accessed by any subclass (derived
class) of that class.
Answer
1. If derived class defines same function as defined in its base class, it is
known as function overriding in C++.
2. It is used to achieve runtime polymorphism.
3. It enables you to provide specific implementation of the function which
is already provided by its base class.
4. For example, we are overriding the eat() function.
#include <iostream>
using namespace std;
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
class Animal {
public:
void eat(){
cout << "Eating...";
}
};
class Dog: public Animal
{
public:
void eat()
{
cout << "Eating bread...";
}
};
int main(void) {
Dog d = Dog();
d.eat();
return 0;
}
Que 5.17. Write a program in C++ to read in two matrices from the
keyboard and compute their sum.
Answer
#include<iostream>
using namespace std;
int main()
{
int row, col, m1[10][10], m2[10][10], sum[10][10];
cout << “Enter the number of rows(should be >1 and <10): ”;
cin >> row;
cout << “Enter the number of column(should be >1 and <10): ”;
cin >> col;
cout << “Enter the elements of first 1st matrix: ”;
for (int i = 0; i < row; i++ ) {
for (int j = 0; j < col; j++ ) {
cin >> m1[i][j];
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
}
}
cout << “Enter the elements of first 1st matrix: ”;
for (int i = 0; i <row; i++ ) {
for (int j = 0; j < col; j++ ) {
cin >> m2[i][j];
}
}
cout << “Output: ”;
for (int i = 0; i < row; i++ ) {
for (int j = 0; j < col; j++ ) {
sum[i][j] = m1[i][j] + m2[i][j];
cout << sum[i][j] << “ ”;
}
}
return 0;
}
Answer
1. Virtual base classes are used in virtual inheritance in a way of preventing
multiple “instances” of a given class appearing in an inheritance hierarchy
when using multiple inheritances.
2. Following is the Syntax for Virtual Base Classes :
Syntax 1:
class B : virtual public A
{
};
Syntax 2 :
class C : public virtual A
{
};
3. For example,
#include <iostream>
using namespace std;
class A {
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
public:
void show()
{
cout << “Hello from A \n”;
}
};
class B : public A {
};
class C : public A {
};
class D : public B, public C {
};
int main()
{
D object;
object.show();
}
PART-4
Polymorphism, Pointers in C++, Pointers and Objects,
this Pointer, Virtual and Pure Virtual Function, Implementing
Polymorphism.
Questions-Answers
Answer
Polymorphism : Refer Q. 1.3, Page 1-3L, Unit-1.
Different types of polymorphism :
1. Compile time polymorphism : This type of polymorphism is achieved
by function overloading or operator overloading.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
a. Function overloading :
i. When there are multiple functions with same name but
different parameters then these functions are said to be
overloaded.
ii. Functions can be overloaded by change in number of arguments
or/and change in type of arguments.
b. Operator overloading : C++ also provides option to overload
operators. For example, we can make the operator ('+') for string
class to concatenate two strings.
2. Runtime polymorphism : This type of polymorphism is achieved by
function overriding :
a. Function overriding :
i. It occurs when a derived class has a definition for one of the
member functions of the base class.
ii. That base function is said to be overridden.
Answer
#include<iostream.h>
#include<conio.h>
void main() {
clrscr();
int *a,*b,*temp;
cout << “Enter value of a and b :”;
cin >> *a >> *b;
temp = a;
a = b;
b = temp;
cout << “nAfter swaping na =”<< *a << “nb =”<< *b;
getch();
}
Answer
Pointer :
1. Pointers are symbolic representation of addresses.
2. They enable programs to simulate call-by-reference as well as to create
and manipulate dynamic data structures.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Answer
1. Objects are the basic run-time entities in an object-oriented system.
2. In the object-oriented programming paradigm object can be a combination
of variables, functions, and data structures.
3. They may represent a person, a place, a bank account, a table of data or
any item that the program has to handle.
4. Programming problem is analyzed in terms of objects and the nature of
communication between them.
5. Program objects should be chosen such that they match closely with the
real-world objects.
6. Objects can interact without having to know details of each other’s data
or code.
Answer
1. In C++ programming, this is a keyword that refers to the current instance
of the class.
2. There can be three main usage of this keyword in C++ :
a. It can be used to pass current object as a parameter to another
method.
b. It can be used to refer current class instance variable.
c. It can be used to declare indexers.
3. For example,
#include <iostream>
using namespace std;
class Employee {
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
public:
int id; //data member (also instance variable)
string name; //data member(also instance variable)
float salary;
Employee(int id, string name, float salary)
{
this->id = id;
this->name = name;
this->salary = salary;
}
void display()
{
cout << id << “ ” << name << “ ” << salary << endl;
}
};
int main(void) {
Employee e1 = Employee(101, “Sonu”, 890000); //creating an object
of Employee
Employee e2 = Employee(102, "Nakul", 59000); //creating an object
of Employee
e1.display();
e2.display();
return 0;
}
Answer
3. Syntax : Syntax :
virtual<func_type> virtual<func_type><func_name>()
<func_name>() = 0;
{
// code
}
4. Definition is given in base class. No definition is given in base
class.
5. Base class having virtual Base class having pure virtual
function can be instantiated i.e., function becomes abstract i.e. it
its object can be made. cannot be instantiated.
6. If derived class does not redefine If derived class does not redefine
virtual function of base class, virtual function of base class,
then it do es not affect then no compilation error but
compilation. derived class also be co me s
abstract just like the base class.
7. All derived class may or may not All derived class must redefine
redefine virtual function of base pure virtual function of base class
class. otherwise derived class also
becomes abstract just like base
class.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
1 Introduction
(2 Marks Questions)
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Ans. An actor is an active object that drives the data flow graph by
producing or consuming values. Actors are attached to the inputs
and outputs of a data flow graph..
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
2 Basic Structural
Modeling
(2 Marks Questions)
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
data entry
generate
processing
output
Fig. 1. Notation for activity states and activity-state transitions.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
CarTransmission Push R
Neutral Reverse
Push N
Push N Push F
Forward
stop upshift upshift
First Second Third
downshift downshift
5. But here by default, the First nested state in the Forward contour
is the initial state and the control is in the First state.
6. Here the Forward is just an abstract state.
7. The event Stop is shared by all the three nested state.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
3
UNIT
Object Oriented
Analysis
(2 Marks Questions)
Ans.
S. No. Early binding Late binding
1. It is a compile-time process. It is a run-time process.
2. The method definition and The method definition and method
method call are linked call are linked during the run time.
during the compile time.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
B.Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2010-11
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
ii. Write a short note on use case diagram and time diagram
with suitable diagram and their utility in system design.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Message C
Method 2
Method 1
Data Data
Method 1
Method 5
Method 3
Method 6
Message B
Message A
Fig. 1. Message passing between objects with encapsulation,
activating methods that can use or modify the data
within their object.
Using message passing to encapsulate the implementation
of an object : Other parts of a system only see an object’s interface
(services it can perform and operation signatures). Internal details
including data are hidden and can only be accessed by a message
that contains a valid signature.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Ans. Polymorphism :
1. Polymorphism means having many forms.
2. Polymorphism is the ability of a message to be displayed in more
than one form.
3. It plays an important role in allowing objects having different
internal structure to share the same external interface.
Applicability of polymorphism :
1. In programming languages there are two types of polymorphism
ad-hoc and universal.
2. There are two kinds of universal polymorphism: parametric and
subtyping.
3. Ad-hoc polymorphism is a kind of polymorphism in which
polymorphic functions can be applied to arguments of different
types.
4. In universal (parametric) polymorphism, the polymorphic functions
are written without mention of any specific type.
5. The ad-hoc polymorphism is applicable in both traditional and object-
oriented programming environments, whereas universal
polymorphism only applies to object-oriented systems.
data entry
generate
processing
output
Fig. 2. Notation for activity states and activity-state transitions.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
A B
C
Multiple inheritance in java :
1. Java does not allow multiple inheritance, and we cannot extend
more than one other class.
2. Java doesn’t allow multiple inheritance to avoid the ambiguity caused
by it.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
3. Links : Links connect objects with actors and are depicted using a
solid line between two elements. Each link is an instance where
messages can be sent.
Link
4. Messages : Messages between objects are shown as a labeled arrow
placed near a link. These messages are communications between
objects that convey information about the activity and can include
the sequence number.
Polymorphism using collaboration diagram :
1. Fig. 3 uses a collaboration diagram to illustrate polymorphism in a
business scenario.
2. The diagram assumes that there are different ways of calculating
an employee’s pay.
3. Full-time employees are paid a salary that depends only on his or
her grade; part-time staff are paid a salary that depends in a similar
way on grade, but must also take into account the number of hours
worked; temporary staff differ in that no deductions are made for
the company pension scheme, but the salary calculation is otherwise
the same as for a full-time employee.
4. An object-oriented system to calculate pay for these employees
might include a separate class for each type of employee, each able
to perform the appropriate pay calculation.
5. However, following the principle of polymorphism, the message
signature for all calculate pay operations is the same.
Fixed monthly
amount depends only
on employee grade
2a:=calculatePay()
:FullTimeEmployee
Variable monthly
amount depends on
1:=getTotal grade and hours
2b:=calculatePay()
Pay()
MonthlyPayPrint :PartTimeEmployee
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Component
Fig. 4. Component.
Component
Component dll
Component A
Realization
Interface Component A
Component A
<<interface>>
Name
Attributes
Operations
Interface name
Fig. 7. Representation of interfaces.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Node1
Communication
path
Node2
ii. Write a short note on use case diagram and time diagram
with suitable diagram and their utility in system design.
Ans. Use case diagrams :
1. Use case diagrams consist of actors, use cases and their
relationships.
2. The diagram is used to model the system/subsystem of an
application.
3. A single use case diagram captures a particular functionality of a
system.
4. Hence to model the entire system, a number of use case diagrams
are used.
Utility of use case diagram in system design :
1. It is used to gather the requirements of a system.
2. It is used to get an outside view of a system.
3. It identifies the external and internal factors influencing the system.
4. It shows the interaction among the requirements of actors.
5. It is used for requirement analysis and high level design.
6. It models the context of a system.
7. It is used in reverse engineering and forward engineering.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
For example :
Vending machine
Buy
beverage
Customer
Perform
scheduled
maintenance
Technician
Make
repairs
Load items
Clerk
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
2. Specialization :
i. Specialization is the reverse process of generalization.
Here, the distinguishing features of groups of objects are
used form specialized classes from existing classes.
ii. It can be said that the subclasses are the specialized
versions of the super-class.
The following figure shows an example of generalization and
specialization.
Vehicle
Specialization
Generalization
Fig. 11.
iii. Modeling association as a class :
1. The purpose of an association is to establish the reasons why
two classes of objects need to know about one another and the
rules that govern the relationship.
2. Modeling an association begins by identifying the participating
classes.
A. Binary association notation :
1. In a class, a binary association documents the rules that govern
one relationship between two classes of object. The association
is rule that explains what is allowed.
2. Fig. 12 shows an association connecting venue class and event
class.
Class Class
Venue Event
Association
Fig. 12.
3.
The venue class defines what a venue object is and what it can
do. The event class defines what an event is and what it can do.
B. Association name :
1. The naming of classes, attributes, and operations is very
important. The usual way to name an association is with a
verb or verb phrase.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Venue Event
hosts
Venue Event
is hoisted by
Fig. 13.
C. Reflexive association : A reflexive association is a very common
phase to use role names. As in following example.
auditor
Venue manager
0..*
Coordinator
Fig. 14.
D. Derived association :
1. A derived association is much like a derived attribute in that it
is not really needed, i.e., the same information could be figured
out by looking at other associations.
2. For example Fig. 15 represents a portion of the theatre system.
0..*
Customer
+ Personal details
+ Account details
+ Loan details
i. Avoid it.
ii. Flatten the class hierarchy.
iii. Break out separate objects.
5. Implement method resolution : Method resolution is one of the
main features of an object-oriented language that is lacking in a
no n-o bject-o rie nted language. Me tho d re solution can be
implemented in following ways :
i. Avoid it.
ii. Resolve methods at compile time.
iii. Resolve methods at run time.
6. Implement associations : Implementing associations in a non-
object-oriented language can be done by :
i. Mapping them into pointers.
ii. Implementing them directly as association container objects.
7. Deal with concurrency :
i. Most languages do not explicitly support concurrency.
ii. Concurrency is usually needed only when more than one
external event occurs, and the behaviour of the program
depends on their timing.
8. Encapsulate internal details of classes :
i. Object-oriented languages provide constructs to encapsulate
implementation.
ii. Some of this encapsulation is lost when object-oriented concept
is translated into a non-object-oriented language, but we can
still take advantage of the encapsulation facilities provided by
the language.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Object 1 Object 2
Message C
Method 2
Method 1
Data Data
Method 1
Method 5
Method 3
Method 6
Message B
Message A
Fig. 16. Message passing between objects with encapsulation,
activating methods that can use or modify the data
within their object.
2. Polymorphism :
i. Polymorphism means having many forms.
ii. Polymorphism is the ability of a message to be displayed in
more than one form.
iii. It plays an important role in allowing objects having different
internal structure to share the same external interface.
3. Inheritance :
a. Inheritance is the ability to create classes that share the
attributes and methods of existing classes, but with more specific
features.
b. Inheritance is mainly used for code reusability.
Difference :
S. No. C++ Java
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
B.Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2011-12
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
3. It causes duplication :
a. OOP projects tend to be easier to design than implement.
b. That is because of the modular classes that are so flexible in
their application.
c. We may be able to get new projects up and running at a greater
speed, but that comes at the cost of having projects sometimes
feel like they have been cloned.
For example :
1. A class is a way of grouping objects that share a number of
characteristics: attributes (like name, color, height, weight, etc.)
and behavior (such as ability to perform jumps, to run, to swim,
etc.).
2. All objects in the class horse will have an attribute named height,
for example. That means that all object in that class have a height-
the value of the attribute height will be different for each instance
of the class (i.e., for each particular horse).
i. A program for laying out a newspaper : Classes that you would
expect in a program for newspaper layout include Page, Column,
Line, Headline, and Paragraph.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
ii. A catalog store order entry system : For a catalog store order
entry system, classes include Customer, Order, Store, and Item.
Vehicle
Generalization
Fig. 1.
Relation to inheritance :
1. Developers use the term generalization or inheritance to refer to
the same concept of reusing shared attributes and operations that
you show in a superclass and reuse in subclasses.
2. Generalization refers to the concept of generalizing from specifics
(the subclasses) to the generic (the superclass).
3. Inheritance refers to the effect of generalization on the subclasses.
Library
1
1
has
contains
* 1.. *
User * reserves Item
*
name Kind
0..1 title
* consults
1
has_copies
*
*
Copy
borrows
* location
status
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
(Polygon)
Next
(Point) Last First (Point)
– 10 10
– 10 – 10
Next
Fig. 3.
Ans.
0..1 1 1
Polygon first Point next
last x : real
0..1 1 y : real1
Fig. 4. General class diagram for polygon and points.
1. Fig. 4 shows the class diagram.
2. Fig. 4 permits a degenerate polygon which consists of exactly one
point. (The same point is first and last. The point is next to itself).
3. The class diagram also permits a line to be stored as a polygon.
4. Fig. 4 does not enforce the constraint that the first and last points
must be adjacent.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
3. Links : Links connect objects with actors and are depicted using a
solid line between two elements. Each link is an instance where
messages can be sent.
Link
4. Messages : Messages between objects are shown as a labeled arrow
placed near a link. These messages are communications between
objects that convey information about the activity and can include
the sequence number.
Polymorphism using collaboration diagram :
1. Fig. 5 uses a collaboration diagram to illustrate polymorphism in a
business scenario.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Activation
occurrence
Fig. 7.
3. Messages : Messages are arrows that represent communication
between objects. Use half-arrowed lines to represent asynchronous
messages. Asynchronous messages are sent from an object that
will not wait for a response from the receiver before continuing its
tasks.
Asynchronous
message
Synchronous
message
Fig. 8.
4. Lifelines : Lifelines are vertical dashed lines that indicate the
object’s presence over time.
Lifeline
Fig. 9.
5. Destroying objects : Objects can be terminated early using an
arrow labeled “<< destroy >>” that points to an X. This object is
removed from memory. When that object's lifeline ends, we can
place an X at the end of its lifeline to denote a destruction occurrence.
6. Loops : A repetition or loop within a sequence diagram is depicted
as a rectangle. Place the condition for exiting the loop at the bottom
left corner in square brackets.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
operate (playerDuration)
permitEntry
holdOpen (doorDuration)
operate
recordEntry (signDuration)
(personID, doorID,
actualTime)
time
Fig. 12. Three parallel queues, each with its own priority.
6. Fig. 13 shows an asynchronous message with its priority level.
7. The property {priority = 3} indicates that the message has a
priority of 3.
transmitMsg (eMailMsg)
{priority = 3}
senderObject: eMailPort:
SomeClass Port
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
* : load ( )
<<broadcast>>
: StartUpSequencer : (Object)
Component
Component
Component dll
Component A
Realization
Interface Component A
Component A
<<interface>>
Name
Attributes
Operations
Interface name
Fig. 18. Representation of interfaces.
2. Basic behavioural modeling:
i. Behavioral models describe the internal dynamic aspects of an
information system that supports the business processes in an
organization.
ii. During analysis, behavioral models describe what the internal
logic of the processes is without specifying how the processes
are to be implemented.
iii. In the design and implementation phases, the detailed design
of the operations contained in the object is fully specified.
iv. There are two types of behavioral models. First, there are
behavioral models that are used to represent the underlying
details of a business process portrayed by a use case model. In
UML, interaction diagrams (sequence and communication) are
used for this type of behavioral model.
v. Second, there is a behavioral model that is used to represent
the changes that occur in the underlying data. UML uses
behavioral state machines for this.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
CheckoutEvent
* *
checkoutDate
dueDate
CheckoutType
dateReturned
1 * /lateCharge
finePerDay
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
i. Avoid it.
ii. Flatten the class hierarchy.
iii. Break out separate objects.
5. Implement method resolution : Method resolution is one of the
main features of an object-oriented language that lacking in a non-
object-oriented language. Method resolution can be implemented
in following ways :
i. Avoid it.
ii. Resolve methods at compile time.
iii. Resolve methods at run time.
6. Implement associations : Implementing associations in a non-
object-oriented language can be done by :
i. Mapping them into pointers.
ii. Implementing them directly as association container objects.
7. Deal with concurrency :
i. Most languages do not explicitly supper concurrency.
ii. Concurrency is usually needed only when more than one
external event occurs, and the behaviour of the program
depends on their timing.
8. Encapsulate internal details of classes :
i. Object-oriented languages provide constructs to encapsulate
implementation.
ii. Some of this encapsulation is lost when object-oriented concept
is translated into a non-object-oriented language, but we can
still take advantage of the encapsulation facilities provided by
the language.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
B. Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2012-13
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
(Person) (Person)
a grandmother a grandfather
Child Child
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Object : myCar
Attributes :
Color = Red
Brand = Hyundai
Model = i20
Methods :
Class : Car Repaint()
Attributes :
Color
Brand
Model
Object : KanikasCar
Methods :
Repaint()
Attributes :
Color = Blue
Brand = Suzuki
Model = S-cross
Methods :
Repaint()
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Methods
Library
1
1
has
contains
* 1.. *
User * reserves Item
*
name Kind
0..1 title
* consults
1
has_copies
*
*
Copy
borrows
* location
status
Fig. 3. Conceptual model for a library system.
ii. Define link and association. Discuss the role of link and
association in object modeling with suitable example.
Ans.
1. Link and association in object modeling represent the relation
between objects and classes.
2. Link : Link defines the relationship between two or more objects
and a link is considered as an instance of an association.
3. Association : It is a group of links that relates objects from the
same classes.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
4. For example :
i. Let us take the two classes Person and Company. Now there is
an association relation between these two classes.
ii. A person may own stock in zero or more companies.
iii. Also it can be related in reverse that a company may have
several persons owing its stock.
iv. The object diagram below shows the links between the objects
of person and company class.
jhon:Person
name=“jhon”
Marry:Person
name=“jhon” jhon:Person
name=“jhon”
James:Person
name=“jhon”
jhon:Person
Sue:Person name=“jhon”
name=“jhon”
Kriti:Person
name=“jhon”
House
Roofs Roofs
Vehicle
Generalization
Fig. 7.
Ans. Polymorphism :
1. Polymorphism means having many forms.
2. Polymorphism is the ability of a message to be displayed in more
than one form.
3. It plays an important role in allowing objects having different
internal structure to share the same external interface.
4. An operation is a function that may be applied to or by objects in a
class.
5. Open, close, hide, and redisplay are operations on class Window.
All objects in a class share the same operations.
6. Each operation has a target object as an implicit argument.
7. The behavior of the operation depends on the class of its target.
8. An object “knows” its class, and hence the right implementation of
the operation.
9. The same operation may apply to many different classes. Such an
operation is polymorphic; i.e., the same operation takes on different
forms in different classes.
10. For example, the class File may have an operation print.
11. Different methods could be implemented to print ASCII files, print
binary files, and print digitized picture files.
12. All these methods logically perform the same task. However, each
method may be implemented by a different piece of code.
(Person) (Person)
a grandmother a grandfather
Child Child
Ans.
A. Difference :
S. No. Class diagram Instance diagram
(PERSON)
Saurabh
26
D. Class Diagram :
<<broadcast>>
: StartUpSequencer : (Object)
registerNewEMailEvent
(urgencyThresh)
newEMailReceived
(highestUrgency)
time
open (time,
highestUrgency)
operate (playerDuration)
permitEntry
holdOpen (doorDuration)
operate
recordEntry (signDuration)
(personID, doorID,
actualTime)
time
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Fig. 14. Three parallel queues, each with its own priority.
6. Fig. 15 shows an asynchronous message with its priority level.
7. The property {priority = 3} indicates that the message has a
priority of 3.
transmitMsg (eMailMsg)
{priority = 3}
senderObject: eMailPort:
SomeClass Port
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
A. Component diagrams :
1. The component diagrams are mainly used to model the static
implementation view of a system.
2. They represent a high-level packaged view of the code.
3. They can be used to model executables, databases and adaptable
systems.
4. Component diagrams mainly contain the following :
i. Components :
a. A component is a physical, replaceable part of a system
that packages implementation and provides the realization
of a set of interfaces.
b. A component is a physical manifestation of an object that
has a well-defined interface and a set of implementations
for the interface.
c. A complex system can be built using software components.
It enhances re-use in the system and facilitates system
evolution.
Component
Component
Component dll
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Component A
Realization
Interface Component A
Component A
<<interface>>
Name
Attributes
Operations
Interface name
Node1
Communication
path
Node2
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Ans.
1. A country has a capital city : It is an association relationship. A
capital city and a country are distinct things so generalization
certainly does not apply. You could argue that a capital city is a part
of a country and thus they are related by aggregation.
2. Files contain records : It is an aggregation relationship. The
word “contain” is a clue that the relationship may be aggregation. A
record is a part of a file. Some attributes and operations on files
propagate to their constituent records.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Object 1 Object 2
Message C
Method 2
Method 1
Data Data
Method 1
Method 5
Method 3
Method 6
Message B
Message A
Fig. 21. Message passing between objects with encapsulation,
activating methods that can use or modify the data
within their object.
2. Polymorphism :
i. Polymorphism means having many forms.
ii. Polymorphism is the ability of a message to be displayed in
more than one form.
iii. It plays an important role in allowing objects having different
internal structure to share the same external interface.
3. Inheritance :
a. Inheritance is the ability to create classes that share the
attributes and methods of existing classes, but with more specific
features.
b. Inheritance is mainly used for code reusability.
a. System
b. Process
c. Technology
8. SA/SD involves two phases :
a. Analysis Phase : It uses Data Flow Diagram, Data Dictionary,
State Transition diagram and ER diagram.
b. Design Phase : It uses Structure Chart and Pseudo Code.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
B. Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2013-14
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Object 1 Object 2
Message C
Method 2
Method 1
Data Data
Method 1
Method 5
Method 3
Method 6
Message B
Message A
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Party
location * children
0..1 parent
Person Organization
For example :
Engineering : Organization
Location = ‘‘Banglore’’
Parent
Parent
Activation
occurrence
Fig. 6.
3. Messages : Messages are arrows that represent communication
between objects. Use half-arrowed lines to represent asynchronous
messages. Asynchronous messages are sent from an object that
will not wait for a response from the receiver before continuing its
tasks.
Asynchronous
message
Synchronous
message
Fig. 7.
4. Lifelines : Lifelines are vertical dashed lines that indicate the
object’s presence over time.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Lifeline
Fig. 8.
5. Destroying objects : Objects can be terminated early using an
arrow labeled “<< destroy >>” that points to an X. This object is
removed from memory. When that object's lifeline ends, we can
place an X at the end of its lifeline to denote a destruction occurrence.
6. Loops : A repetition or loop within a sequence diagram is depicted
as a rectangle. Place the condition for exiting the loop at the bottom
left corner in square brackets.
registerNewEMailEvent
(urgencyThresh)
newEMailReceived
(highestUrgency)
time
open (time,
highestUrgency)
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Ans.
S. No. Procedural Oriented Object-Oriented
Programming Programming
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
B. Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2014-15
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Node1
Communication
path
Node2
PackageName
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
data entry
generate
processing
output
calledPhoneHangsUp
Warning Timeout Recorded Message
onHook
timeout
Initial Pseudo State digit(n) invalidNumber
timeout
calledPhoneAnswers calledPhoneHangsUp
lOMoARcPSD|22022671
numberBusy trunkBusy
Downloaded by KS ([email protected])
Fig. 5. State machine diagram for answering a telephone call.
SP–9 A(CS-Sem-5)
lOMoARcPSD|22022671
<<signal>>
TrainDeparture
train
trainNumber
city
date
Fig. 6.
B. Time event :
1. A time event is an event caused by the occurrence of an
absolute time or the elapse of a time interval.
2. For example, Fig. 7 shows, the UML notation for an absolute
time is the keyword when followed by a parenthesized
expression involving time. The notation for time interval is
the keyword after followed by a parenthesized expression
that evaluates to a time duration.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
1. Class definitions :
i. The first step in implementing an object-oriented design
is to declare object classes. Each attribute and operation
in an object diagram must be declared as part of its
corresponding class.
ii. Assign data types to attributes. Declare attributes and
operations as either public or private.
2. Creating objects :
i. Object-oriented languages create new objects in following
two ways :
a. Class operation applied to a class object creates a
new object of the class.
b. Using special operations that create new objects.
ii. When a new object is created, the language allocates
storage for its attribute values and assigns it a unique
object ID.
3. Calling operations :
i. In most object-oriented languages, each operation has at
least one implicit argument, the target object, indicated
with a special syntax.
ii. Operations may or may not have additional arguments.
4. Using Inheritance :
i. To implement inheritance object-oriented languages use
different mechanisms.
ii. There are three independent dimensions for classifying
inheritance mechanisms :
a. Static or dynamic
b. Implicit or explicit
c. Per object or per group.
iii. Many of the popular languages are static, implicit and per
group.
5. Implementing associations :
i. There are two approaches to implement associations :
Buried pointers and distinct association objects.
ii. If the language does not explicitly support association
objects then buried pointers are easy to implement.
iii. An association can also be implemented as a distinct
container object.
Ans.
1. Jackson System Development (JSD) is a method of system
development that covers the software life cycle either directly or by
providing a framework into which more specialized techniques can
fit.
2. JSD can start from the stage in a project when there is only a
general statement of requirements.
3. Following are the phases of JSD :
a. Modeling phase : In the modeling phase, the designer creates
a collection of entity structure diagrams and identifies the
entities in the system, the actions they perform, the attributes
of the actions and time ordering of the actions in the life of the
entities.
b. Specification phase : This phase focuses on actually what is
to be done. Major goal is to map progress in the real world on
progress in the system that models it.
c. Implementation phase :
i. In the implementation phase JSD determines how to
obtain the required functionality.
ii. Imple me ntatio n way of the syste m is based o n
transformation of specification into efficient set of
processes.
Problem
Domain
Representation Design
Solution Domain
Representation
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
B. Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2015-16
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Section-A
1. Attempt all parts. All parts carry equal marks. Write answer of
each part in short (2 × 10 = 20)
a. What is nested state diagram ? Explain with suitable
example.
Section-C
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Section-A
1. Attempt all parts. All parts carry equal marks. Write answer of
each part in short (2 × 10 = 20)
a. What is nested state diagram ? Explain with suitable
example.
Ans.
1. A nested state diagram is used to model the complex system as the
regular state diagram is inadequate in describing the large and
complex problem.
2. The nested state diagram is the concept of advanced state
modeling.
For example :
CarTransmission Push R
Neutral Reverse
Push N
Push N Push F
Forward
stop upshift upshift
First Second Third
downshift downshift
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
For example :
data entry
generate
processing
output
Section-B
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Ans.
S. No. Architectural Modeling Behavioral Modeling
Programmable thermostat
Furnace relay
[temp < target temp
and season switch in Heat]
Fig. 1.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Section-C
b. Applet in java
Ans. This question is out of syllabus from session 2020-21.
c. JDBC in Java
Ans. This question is out of syllabus from session 2020-21.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
b. Actors
Ans.
1. An actor is an active object that drives the data flow graph by
producing or consuming values.
2. Actors are attached to the inputs and outputs of a data flow graph.
3. Examples of actors include the user of a program, a thermostat,
and a motor under computer control.
4. An actor is drawn as a rectangle to show that it is an object.
Arrows between the actor and the diagram are inputs and outputs
of the diagram.
c. Control flow
Ans.
1. A data flow diagram shows all possible computation paths for
values; it does not show which paths are executed and in what
order.
2. This is done by including control flows in the data flow diagram.
3. A control flow is a Boolean value that affects whether a process is
evaluated.
4. The control flow is not an input value to the process itself.
5. A control flow is shown by a dotted line from a process producing
a Boolean value to the process being controlled.
Downloaded by KS ([email protected])
lOMoARcPSD|22022671
Downloaded by KS ([email protected])