Object Oriented System Design Quantum
Object Oriented System Design Quantum
in
1
www.aktutor.in
QUANTUM SERIES
For
B.Tech Students of Third Year
of All Engineering Colleges Affiliated to
Dr. A.P.J. Abdul Kalam Technical University,
Uttar Pradesh, Lucknow
(Formerly Uttar Pradesh Technical University)
Kanika Dhama
TM
1 Introduction
CONTENTS
Part-1 : Introduction, The Meaning ..................... 1–2L to 1–11L
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
(bank account) are modeled as object.
Object Oriented System Design 1–3 L (CS/IT-Sem-5)
www.aktutor.in
2. Attributes : They describe information about the object.
3. Behavior :
a. It specifies what the object can do.
b. It defines the operation performed on objects.
4. Class :
a. A class encapsulates the data and its behavior.
b. Objects with similar meaning and purpose grouped together as
class.
5. Methods :
a. Methods determine the behavior of a class.
b. They are nothing more than an action that an object can perform.
6. Message :
a. A message is a function or procedure call from one object to another.
b. They are information sent to objects to trigger methods.
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
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.
Object Oriented System Design 1–5 L (CS/IT-Sem-5)
www.aktutor.in
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
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.
Introduction 1–8 L (CS/IT-Sem-5)
www.aktutor.in
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.
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.
Object Oriented System Design 1–9 L (CS/IT-Sem-5)
www.aktutor.in
4. One may want to change the implementation of an object to improve
performance, fix a bug, consolidate code, or for porting.
5. To understand encapsulation, let us consider the object ‘Employee’.
6. The attributes of employees say ‘salary’ is kept hidden inside the object
and may be made accessible only through the method meant for the
purpose.
7. The method resides within the object.
For example, if getSalary() is a method of the object ‘Employee’ to get
the salary of an employee, then the salary of an employee can be obtained
by no other way but by this method.
8. Other objects can also send messages to the object ‘Employee’ and get
the salary of an employee by the getSalary() method.
9. Other objects need not be concerned with the attributes and internal
structure of the object.
10. This is shown in Fig. 1.9.1. The figure shows that attributes are hidden
inside the object by a method.
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.
Introduction 1–10 L (CS/IT-Sem-5)
www.aktutor.in
4. Encapsulation is a common technique programmers use to implement
information hiding.
5. Advantage of information hiding is yielding flexibility, such as allowing
a programmer to more readily modify a program.
6. This also may be done by placing source code within modules for easy
access in the future, as the program develops and evolves.
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.
Object Oriented System Design 1–11 L (CS/IT-Sem-5)
www.aktutor.in
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 :
Introduction 1–12 L (CS/IT-Sem-5)
www.aktutor.in
a. Testing a physical entity before building it :
i. Simulating a model is cheaper. Also, it provides information that
is too inaccessible to be measured from physical model.
ii. Computer models are usually cheaper than building a complete
system and it enable flaws to be corrected early.
For example : Scale models of airplane and cars are tested in wind
tunnels to improve their aerodynamic.
b. Communication with customers :
i. Software designers build models to show their customers.
For example : Demonstration products like mock-ups that imitate some
or all of the external behavior of a system.
c. Visualization :
i. Storyboards of movies, television shows, and advertisements allow
the writers to see how their idea flows.
ii. Using models unnecessary segments can be modified before the
final development begins.
d. Reduction of complexity :
i. Modeling helps in understanding the systems that are too complex
to understand directly.
ii. Model reduces complexity by leaving out the non essential details.
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.
Object Oriented System Design 1–13 L (CS/IT-Sem-5)
www.aktutor.in
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.
Introduction 1–14 L (CS/IT-Sem-5)
www.aktutor.in
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.
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.
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
Introduction 1–16 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented System Design 1–17 L (CS/IT-Sem-5)
www.aktutor.in
Person OwnsStock Company
Name * * Name
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.
Introduction 1–18 L (CS/IT-Sem-5)
www.aktutor.in
c. The system designer must decide what performance characteristics
to optimize, developing strategy for solving the problem, and
making tentative resource allocations.
d. For example, the system designer might decide that changes to
the workstation screen must be fast and smooth and choose an
appropriate communications protocol and memory buffering
strategy.
3. Object design :
a. The object designer builds a design model based on the analysis
model but containing implementation details.
b. The designer adds details to the design model in accordance with
the strategy established during system design.
c. The focus of object design is the data structures and algorithms
needed to implement each class.
d. The object classes are augmented with computer-domain data
structures and algorithms chosen to optimize important
performance measures.
e. For example, the Window class operations are now specified in
terms of the underlying hardware and operating system.
4. Implementation :
a. The object classes and relationships developed during object design
are finally implemented.
b. During implementation, it is important to follow good software
engineering practice so that traceability to the design is straight-
forward and so that the implemented system remains flexible and
extensible.
c. For example, the Window class would be coded in a programming
language, using calls to the underlying graphics system on the
workstation.
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.
Introduction 1–20 L (CS/IT-Sem-5)
www.aktutor.in
4. It is also used to model non-software systems as well.
5. UML is not a programming language but tools can be used to generate
code in various languages using UML diagrams.
6. UML has a direct relation with object-oriented analysis and design.
Conceptual model of UML :
1. A conceptual model is defined as a model which is made of concepts and
their relationships.
2. A conceptual model is the first step before drawing a UML diagram.
3. It helps to understand the entities in the real world and how they interact
with each other.
4. The conceptual model of UML has three major elements :
a. UML building blocks.
b. Rules to connect the building blocks.
c. Common mechanisms of UML.
5. A domain model, often referred to as a conceptual model, might be
represented by a particular kind of UML class diagram.
6. This model explains the structure of the application domain rather than
the application structure itself.
7. It focuses on the domain concepts, rather than on the software entities.
8. Fig. 1.20.1 shows the conceptual model for a library system.
Library
1
1
has
contains
* 1.. *
User * reserves Item
*
name Kind
0..1 title
* consults
1
has_copies
*
*
Copy
borrows
* location
status
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.
Introduction 1–22 L (CS/IT-Sem-5)
www.aktutor.in
2. The UML is defined within a conceptual framework for modeling that
consists of four distinct layers or levels of abstraction.
3. This framework is based on the most fundamental UML notation that
concepts are depicted as symbols, and relationships among concepts
are depicted as paths (lines) connecting symbols. Both of these types of
elements may be named.
4. The concepts introduced by the UML are organized around architectural
views to define the various diagrams.
5. The UML diagrams are used to understand for conceptualize a problem,
solve the problem, and implement or realize the solution.
Object Oriented System Design 2–1 L (CS/IT-Sem-5)
www.aktutor.in
2 Basic Structural
Modeling
CONTENTS
Part-1 : Basic Structural Modeling, ....................... 2–2L to 2–8L
Class, Relationships, Common
Mechanism and Diagram
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.
Object Oriented System Design 2–3 L (CS/IT-Sem-5)
www.aktutor.in
c. Architectural model can be defined as the blueprint of the entire
system.
d. Package diagram comes under architectural modeling.
UML : Refer Q. 1.20, Page 1-19L, Unit-1.
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.
Basic Structural Modeling 2–4 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented System Design 2–5 L (CS/IT-Sem-5)
www.aktutor.in
B. Deployment diagrams : They display the configuration of run-
time processing elements and the software components, processes
and objects. The deployment diagram contains nodes and connections.
A node is a piece of hardware in the system. A connection depicts the
communication path used by the hardware (Fig. 2.2.5).
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.
Basic Structural Modeling 2–6 L (CS/IT-Sem-5)
www.aktutor.in
b. Dependency is represented by a dotted arrow as shown in the
following figure.
c. The arrow head represents the independent element and the other
end represents the dependent element.
d. Dependency is used to represent the dependency between two
elements of a system
2. Association Notation :
a. Association describes how the elements in a UML diagram are
associated.
b. In simple words, it describes how many elements are taking part in
an interaction.
c. Association is represented by a dotted line with (without) arrows
on both sides.
d. The two ends represent two associated elements as shown in the
following figure.
e. The multiplicity is also mentioned at the ends (1, *, etc.) to show
how many objects are associated.
3. Generalization Notation :
a. Generalization describes the inheritance relationship of the object-
oriented world.
b. It is a parent and child relationship.
c. Generalization is represented by an arrow with a hollow arrow
head as shown in the following figure.
d. One end represents the parent element and the other end
represents the child element.
4. Extensibility Notation :
a. All the languages (programming or modeling) have some
mechanism to extend its capabilities such as syntax, semantics, etc.
b. UML also has the following mechanisms to provide extensibility
features :
i. Stereotypes (Represents new elements)
ii. Tagged values (Represents new attributes)
iii. Constraints (Represents the boundaries)
c. Extensibility notations are used to enhance the power of the
language.
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).
Basic Structural Modeling 2–8 L (CS/IT-Sem-5)
www.aktutor.in
3. Inheritance refers to the effect of generalization on the subclasses.
Aggregation :
1. Aggregation is a stronger form of association. It represents the has-a or
part-of relationship.
2. An aggregation association depicts a complex object that is composed of
other objects.
3. For example, we may characterize a house in terms of its roof, floors,
foundation, walls, rooms, windows, and so on. A room may, in turn be,
composed of walls, ceiling, floor, windows, and doors, as represented in
Fig. 2.5.2.
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.
Object Oriented System Design 2–9 L (CS/IT-Sem-5)
www.aktutor.in
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.
Basic Structural Modeling 2–10 L (CS/IT-Sem-5)
www.aktutor.in
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
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.
Basic Structural Modeling 2–12 L (CS/IT-Sem-5)
www.aktutor.in
1. Fig. 2.9.2 shows the class diagram.
2. Fig. 2.9.2 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. 2.9.2 does not enforce the constraint that the first and last points
must be adjacent.
5. In Fig. 2.9.2 the sense of ordering is problematic. A polygon that is
traversed in left-to-right order is stored differently than one that is
traversed in right-to-left order even though both visually appear the
same.
6. There is no constraint that a polygon be closed and that a polygon not
cross itself.
7. In general it is difficult to fully capture constraints with class models and
we must choose between model complexity and model completeness.
Mate
(Person) (Person)
a grandmother a grandfather
Child Child
Fig. 2.10.1.
(PERSON)
Saurabh
26
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.
Basic Structural Modeling 2–16 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented System Design 2–17 L (CS/IT-Sem-5)
www.aktutor.in
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.
Iterated messages :
1. Collaboration diagrams use syntax similar to sequence diagrams to
indicate that either a message iterates (is run multiple times) or is run
conditionally.
2. We can indicate that a particular message iterates by prefixing a message
sequence number with an iteration expression.
3. We can simply use an asterisk (*) to indicate that a message runs more
than once, or we can get more specific and show the number of times a
message is repeated.
4. To indicate that a message is run conditionally, we can prefix the message
sequence number with a conditional clause such as [x = true].
5. This indicates that the message is sent only if the condition is met.
6. The UML leaves the syntax of conditional clauses wide open, so we can
create expressions that make sense in the context of our application.
Use of self in message :
1. Self represents the ability of an object to send a message to itself.
2. Messages in collaboration diagrams are shown as arrows pointing from
the client object to the supplier object.
3. Messages represent a client invoking an operation on a supplier object.
4. Message icons have one or more messages associated with them.
5. Messages are composed of message text prefixed by a sequence number.
6. This sequence number indicates the time-ordering of the message.
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.
Object Oriented System Design 2–19 L (CS/IT-Sem-5)
www.aktutor.in
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>>
: 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.
Basic Structural Modeling 2–22 L (CS/IT-Sem-5)
www.aktutor.in
2. The target object continuous with other activities while it monitors
for the occurrence of an event of the registered type.
registerNewEMailEvent
(urgencyThresh)
newEMailReceived
(highestUrgency)
time
open (time,
highestUrgency)
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.
Basic Structural Modeling 2–24 L (CS/IT-Sem-5)
www.aktutor.in
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
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.
Diagram :
calledPhoneHangsUp
Warning Timeout Recorded Message
onHook
timeout
Initial Pseudo State digit(n) invalidNumber
timeout
calledPhoneAnswers calledPhoneHangsUp
onHook digit(n) routed
Idle Tial Tone Dialing Connecting Ringing Connected Disconnected
valid Number
numberBusy trunkBusy
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.
Basic Structural Modeling 2–30 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented System Design 2–31 L (CS/IT-Sem-5)
www.aktutor.in
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.
Fig. 2.23.1. Use case summaries for a vending machine.
Use case diagrams are divided as :
1. Use case diagram are divided into three use cases diagrams i.e., Order,
SpecialOrder, NormalOrder and one actor which is the customer.
2. The SpecialOrder and NormalOrder use cases are extended from Order
use case.
3. Hence, they have extended relationship.
4. The actor Customer lies outside the system as it is an external user of
the system.
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.
Basic Structural Modeling 2–32 L (CS/IT-Sem-5)
www.aktutor.in
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
Component A
Realization
Interface Component A
Component A
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
Object Oriented System Design 3–1 L (CS/IT-Sem-5)
www.aktutor.in
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
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 :
Object Oriented System Design 3–3 L (CS/IT-Sem-5)
www.aktutor.in
a. Restructuring the class data (if necessary),
b. Implementation of methods, i.e., internal data structures and algorithms,
c. Implementation of control, and
d. Implementation of associations.
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.
Object Oriented Analysis 3–4 L (CS/IT-Sem-5)
www.aktutor.in
b. Flexibility : Flexibility determines whether the chosen algorithm can
be implemented suitably, without loss of appropriateness in various
environments.
c. Understandability : This determines whether the chosen algorithm
is easy to understand and implement.
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).
Object Oriented System Design 3–5 L (CS/IT-Sem-5)
www.aktutor.in
OOAD attachment with OMT :
1. Object Modeling Technique (OMT) combines the three views of modeling
systems.
2. The object model represents the static, structural, “data” aspects of a
system.
3. The dynamic model represents the temporal, behavioral, “control” aspects
of a system.
4. The functional model represents the transformational, “function” aspects
of a system.
5. A typical object oriented software procedure incorporates all three
aspects : It uses data structures (object model), it sequences operations
in time (dynamic model), and it transforms values (functional model).
Each model contains references to entities in other models.
6. For example, operations are attached to objects in the object model but
more fully expanded in the functional model.
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.
Object Oriented Analysis 3–6 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented System Design 3–7 L (CS/IT-Sem-5)
www.aktutor.in
For example : Consider the design of a company’s employee skills
database. Fig. 3.7.1 shows a portion of the analysis class model. The
operation companyfindskill() returns a set of persons in the company
with a given skill. For example, an application might need all the
employees who speak Japanese.
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 :
Object Oriented Analysis 3–8 L (CS/IT-Sem-5)
www.aktutor.in
a. Static Models : To describe the static structure of a system using class
diagrams and object diagrams.
b. Dynamic Models : To describe the dynamic structure of a system and
show the interaction between classes using interaction diagrams and
state-chart diagrams.
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 :
Object Oriented System Design 3–9 L (CS/IT-Sem-5)
www.aktutor.in
a. Classes in a module should represent similar things or components
in the same composite object.
b. Closely connected classes should be in the same module.
c. Unconnected or weakly connected classes should be placed in
separate modules.
d. Modules should have good cohesion, i.e., high cooperation among
its components.
e. A module should have low coupling with other modules, i.e.,
interaction or interdependence between modules should be
minimum.
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.
Object Oriented Analysis 3–10 L (CS/IT-Sem-5)
www.aktutor.in
3. Make them public :
a. The documentation of the processes must be available to all team
and company members.
b. Restricting access to documentation creates the false illusion that
it’s only relevant to a particular group.
4. Flexible documentation :
a. Companies change, update, improve, so their processes are also
subject to constant changes. To improve the effectiveness of the
process, incorpo rate the necessary adjustments to the
documentation of the process.
b. Document the date of the last update.
c. Save a backup copy of the files that document the process.
d. Review the documents at least once a year.
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
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.
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.
Object Oriented Analysis 3–14 L (CS/IT-Sem-5)
www.aktutor.in
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. Implementation way of the system is based on transformation
of specification into efficient set of processes.
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.
Object Oriented System Design 3–15 L (CS/IT-Sem-5)
www.aktutor.in
4. Implement inheritance in data structures : Following ways are
use to implement data structures for inheritance in a non-object-oriented
language :
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 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 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.
Que 3.19. Write short note on translating object oriented design
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 :
Object Oriented Analysis 3–16 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented System Design 3–17 L (CS/IT-Sem-5)
www.aktutor.in
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
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.
Object Oriented System Design 3–19 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented Analysis 3–20 L (CS/IT-Sem-5)
www.aktutor.in
iv. There should be separate policy and implementation.
v. Provide uniform average.
vi. Broaden the method as much as possible.
vii. Avoid global information.
viii. Avoid modes.
ii. Robustness :
1. A method is robust if it does not fail even if it receives improper
parameters.
2. Robustness against internal bugs may be traded off against efficiency.
3. Robustness against user errors should never be sacrificed.
4. Rules for robustness :
a. Protect against errors : Software should protect itself against
incorrect user input. Incorrect user input should never cause a
crash.
b. Optimize after the program runs : Don’t optimize a program
until you get it working.
c. Validate arguments : External operations, those available to users
of the class, must rigorously check their arguments to prevent
failure. Don’t include arguments that cannot be validated.
d. Avoid predefined limits : When possible use dynamic memory
allocation to create data structures that do not have predefined
limits.
e. Instrument the program for debugging and performance
monitoring : You should instrument your code for debugging,
statistics, and performance. The level of debugging that you must
build into your code depends on the programming environment
presented by the language.
iii. Extensibility :
1. Extensibility is a software engineering and systems design principle
that provides for future growth.
2. Extensibility is a measure of the ability to extend a system and the level
of effort required to implement the extension.
3. Extensions can be through the addition of new functionality or through
modification of existing functionality.
4. The principle provides for enhancements without impairing existing
system functions.
For example : Object-oriented application frameworks which achieve
extensibility typically by using inheritance and dynamic binding.
iv. Abstraction :
1. Abstraction is the selective examination of certain aspects of a problem.
2. The goal of abstraction is to isolate those aspects that are important for
some purpose and suppress those aspects that are unimportant.
Object Oriented System Design 3–21 L (CS/IT-Sem-5)
www.aktutor.in
3. Abstraction must always be for some purpose, because the purpose
determines what is and is not important.
4. Many different abstractions of the same thing are possible, depending
on the purpose for which they are made.
Que 3.24. Compare Abstraction and Encapsulation.
Answer
Object Oriented System Design 4–1 L (CS/IT-Sem-5)
www.aktutor.in
CONTENTS
Part-1 : C++ Basics, Overview, ............................. 4–2L to 4–10L
Program Structure, Namespace,
Identifiers, Variables,
Constants, Enum, Operators,
Typecasting, Control Structures
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 definition).
Object Oriented System Design 4–3 L (CS/IT-Sem-5)
www.aktutor.in
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.
C++ Basics & Functions 4–4 L (CS/IT-Sem-5)
www.aktutor.in
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;
Object Oriented System Design 4–5 L (CS/IT-Sem-5)
www.aktutor.in
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++ ?
C++ Basics & Functions 4–6 L (CS/IT-Sem-5)
www.aktutor.in
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 are the types of typecasting :
Object Oriented System Design 4–7 L (CS/IT-Sem-5)
www.aktutor.in
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>.
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’)
C++ Basics & Functions 4–10 L (CS/IT-Sem-5)
www.aktutor.in
{
++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.
Object Oriented System Design 4–11 L (CS/IT-Sem-5)
www.aktutor.in
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.
C++ Basics & Functions 4–12 L (CS/IT-Sem-5)
www.aktutor.in
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.
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;
C++ Basics & Functions 4–14 L (CS/IT-Sem-5)
www.aktutor.in
cout << “Enter the number : ”;
cin >> val;
num = val;
while (num != 0)
{
sum = sum + num % 10;
num = num / 10;
}
cout << “The sum of the digits of ”
<< val << “ is “ << sum;
}
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()
Object Oriented System Design 4–15 L (CS/IT-Sem-5)
www.aktutor.in
{
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.
C++ Basics & Functions 4–16 L (CS/IT-Sem-5)
www.aktutor.in
2. It also saves the overhead of push/pop variables on the stack when
function is called.
3. It also saves overhead of a return call from a function.
4. When you inline a function, you may enable compiler to perform context
specific optimization on the body of function. Such optimizations are not
possible for normal function calls. Other optimizations can be obtained
by considering the flows of calling context and the called context.
5. Inline function may be useful (if it is small) for embedded systems because
inline can yield less code than the function call preamble and return.
B. Disadvantages :
1. The added variables from the inlined function consume additional
registers.
2. If you use too many inline functions then the size of the binary executable
file will be large, because of the duplication of same code.
3. Too much inlining can also reduce your instruction cache hit rate, thus
reducing the speed of instruction fetch from that of cache memory to
that of primary memory.
4. Inline function may increase compile time overhead if someone changes
the code inside the inline function then all the calling location has to be
recompiled because compiler would require to replace all the code once
again to reflect the changes, otherwise it will continue with old
functionality.
5. Inline functions may not be useful for many embedded systems. Because
in embedded systems code size is more important than speed.
Answer
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:
C++ Basics & Functions 4–18 L (CS/IT-Sem-5)
www.aktutor.in
static int add(int a,int b){
return a + b;
}
static int add(int a, int b, int c)
{
return a + b + c;
}
};
int main(void) {
Cal C; // class object declaration.
cout << C.add(10, 20) << endl;
cout << C.add(12, 20, 23);
return 0;
}
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;
Object Oriented System Design 4–19 L (CS/IT-Sem-5)
www.aktutor.in
cout<<“Length of box:”<< printLength(b)<<endl;
return 0;
}
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>
C++ Basics & Functions 4–20 L (CS/IT-Sem-5)
www.aktutor.in
using namespace std;
// A function with default arguments, it can be called with
// 2 arguments or 3 arguments or 4 arguments.
int sum(int x, int y, int z=0, int w=0)
{
return (x + y + z + w);
}
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.
Object Oriented System Design 4–21 L (CS/IT-Sem-5)
www.aktutor.in
5. It can be declared either in the private or the public part.
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.
Object Oriented System Design 5–1 L (CS/IT-Sem-5)
www.aktutor.in
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
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;
};
Object Oriented System Design 5–3 L (CS/IT-Sem-5)
www.aktutor.in
6. The class declaration is similar to a struct declaration. The keyword
class specifies that what follows is an abstract data of type class_name.
7. The body of a class is enclosed within braces and terminated by a
semicolon.
8. The class body contains the declaration of variables and functions. These
functions and variables are collectively called class members.
9. The class members that have been declared as private can be accessed
only from within the class.
10. While the public members can be accessed from outside the class also.
11. The variables declared inside the class are known as data members and
the functions are known as member functions.
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)
Objects and Classes 5–4 L (CS/IT-Sem-5)
www.aktutor.in
{
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
Object Oriented System Design 5–5 L (CS/IT-Sem-5)
www.aktutor.in
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.
Objects and Classes 5–6 L (CS/IT-Sem-5)
www.aktutor.in
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).
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.
Objects and Classes 5–8 L (CS/IT-Sem-5)
www.aktutor.in
6. A destructor should be declared in the public section of the class.
7. The programmer cannot access the address of destructor.
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.
}
Object Oriented System Design 5–9 L (CS/IT-Sem-5)
www.aktutor.in
Que 5.11. What are the rules of operator overloading ?
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.
Objects and Classes 5–10 L (CS/IT-Sem-5)
www.aktutor.in
b. Following is the syntax :
(type) expression
where type indicates the data type to which the final result
is converted.
ii. Conversion using Cast operator :
Inheritance : concept of inheritance, types of inheritance: single,
multiple, multilevel, hierarchical , hybrid, protected
members, overriding, virtual base class
a. A cast operator is a unary operator which forces one data
type to be converted into another data type.
b. C++ supports four types of casting :
i. Static Cast
ii. Dynamic Cast
iii. Const Cast
iv. Reinterpret Cast
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.
Object Oriented System Design 5–11 L (CS/IT-Sem-5)
www.aktutor.in
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
};
Objects and Classes 5–12 L (CS/IT-Sem-5)
www.aktutor.in
3. Multilevel inheritance : In this type of inheritance, a derived class is
created from another derived class.
4. Hierarchical inheritance : In this type of inheritance, more than one
sub class is inherited from a single base class, i.e., more than one derived
class is created from a single base class.
5. Hybrid (Virtual) inheritance :
a. Hybrid inheritance is implemented by combining more than one
type of inheritance.
b. For example : Combining Hierarchical inheritance and Multiple
Inheritance.
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;
Object Oriented System Design 5–13 L (CS/IT-Sem-5)
www.aktutor.in
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];
Objects and Classes 5–14 L (CS/IT-Sem-5)
www.aktutor.in
}
}
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 {
Object Oriented System Design 5–15 L (CS/IT-Sem-5)
www.aktutor.in
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.
Objects and Classes 5–16 L (CS/IT-Sem-5)
www.aktutor.in
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.
Object Oriented System Design 5–17 L (CS/IT-Sem-5)
www.aktutor.in
3. Its general declaration in C++ has the format :
datatype *var_name;
int *ptr; //ptr can point to an address
Use a pointer :
1. Define a pointer variable
2. Assigning the address of a variable to a pointer using unary operator (&)
which returns the address of that variable.
3. Accessing the value stored in the address using unary operator (*)
which returns the value of the variable located at the address specified
by its operand.
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 {
Objects and Classes 5–18 L (CS/IT-Sem-5)
www.aktutor.in
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
Object Oriented System Design SQ–1 L (CS/IT-Sem-5)
www.aktutor.in
1 Introduction
(2 Marks Questions)
2 Marks Questions SQ–4 L (CS/IT-Sem-5)
www.aktutor.in
2 Basic Structural
Modeling
(2 Marks Questions)
data entry
generate
processing
output
Fig. 1. Notation for activity states and activity-state transitions.
Object Oriented System Design SQ–7 L (CS/IT-Sem-5)
www.aktutor.in
2.20. Discuss the synchronization of concurrent activities.
AKTU 2015-16, Marks 02
Ans.
1. Sometimes one object must perform two (or more) activities
concurrently.
2. The object does not synchronize the internal steps of the activities
but must complete both activities before it can progress to its next
state.
3. For example, a cash dispensing machine dispenses cash and returns
the user’s card at the end of a transaction. The machine must not
reset itself until the user takes both the cash and the card, but the
user may take them in either order or even simultaneously.
CarTransmission Push R
Neutral Reverse
Push N
Push N Push F
Forward
stop upshift upshift
First Second Third
downshift downshift
Object Oriented System Design SQ–9 L (CS/IT-Sem-5)
www.aktutor.in
3
UNIT
Object Oriented
Analysis
(2 Marks Questions)
2 Marks Questions SQ–12 L (CS/IT-Sem-5)
www.aktutor.in
2 Marks Questions SQ–14 L (CS/IT-Sem-5)
www.aktutor.in
Object Oriented Techniques SP–1 A (CS-Sem-5)
www.aktutor.in
B.Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2010-11
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
ii. Write a short note on use case diagram and time diagram
with suitable diagram and their utility in system design.
Solved Paper (2010-11) SP–4 A (CS-Sem-5)
www.aktutor.in
SOLUTION OF PAPER (2010-11)
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.
data entry
generate
processing
output
Fig. 2. Notation for activity states and activity-state transitions.
Solved Paper (2010-11) SP–6 A (CS-Sem-5)
www.aktutor.in
ii. Define an abstract class. When is it required to create an
abstract class ? Explain it with an example.
Ans. Abstract class :
1. An abstract class is a class that contains at least one abstract method.
2. An abstract method is a method that is declared, but not instantiated.
When to create an abstract class :
1. An abstract class is created when we are using the inheritance
concept since it provides a common base class implementation to
derived classes.
2. An abstract class is used when we want to declare non-public
members.
3. If we want to add new methods in the future, then an abstract class
is used.
4. If we want to create multiple versions of our component, we create
an abstract class.
5. If we want to provide common, implemented functionality among
all implementations of our component, we use an abstract class.
For example :
//abstract parent class
abstract class animal{
//abstract method
public abstract void sound();
}
//Dog class extends animal class
public class dog extends animal{
public void sound(){
System.out.println(“Woof”)’
}
public static void main(String args[]){
animal obj = new dog();
obj.sound();
}
}
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.
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
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.
Solved Paper (2010-11) SP–12 A (CS-Sem-5)
www.aktutor.in
B. Deployment diagrams : They display the configuration of run-
time processing elements and the software components, processes
and objects. The deployment diagram contains nodes and connections.
A node is a piece of hardware in the system. A connection depicts the
communication path used by the hardware (Fig. 8).
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.
Object Oriented Techniques SP–13 A (CS-Sem-5)
www.aktutor.in
For example :
Vending machine
Buy
beverage
Customer
Perform
scheduled
maintenance
Technician
Make
repairs
Load items
Clerk
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.
Solved Paper (2010-11) SP–16 A (CS-Sem-5)
www.aktutor.in
2. The Fig. 13 shows the name association modeled with two
different names using verb “hosts” and a verb phrase “is hoisted
by”.
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
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
Object Oriented Techniques SP–1 A (CS-Sem-5)
www.aktutor.in
B.Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2011-12
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Solved Paper (2011-12) SP–4 A (CS-Sem-5)
www.aktutor.in
SOLUTION OF PAPER (2011-12)
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.
Solved Paper (2011-12) SP–6 A (CS-Sem-5)
www.aktutor.in
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
(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.
Solved Paper (2011-12) SP–10 A (CS-Sem-5)
www.aktutor.in
5. In Fig. 4 the sense of ordering is problematic. A polygon that is
traversed in left-to-right order is stored differently than one that is
traversed in right-to-left order even though both visually appear
the same.
6. There is no constraint that a polygon be closed and that a polygon
not cross itself.
7. In general it is difficult to fully capture constraints with class models
and we must choose between model complexity and model
completeness.
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.
Object Oriented Techniques SP–11 A (CS-Sem-5)
www.aktutor.in
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
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.
Object Oriented Techniques SP–13 A (CS-Sem-5)
www.aktutor.in
A. Asynchronous messages without priority :
1. An asynchronous message can be implemented on the
sequence diagram by using a half arrowhead on the
asynchronous message arrow.
asyncMessage1 (inputArg)
senderObject: targetObject:
Class1 Class2
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
<<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.
Object Oriented Techniques SP–17 A (CS-Sem-5)
www.aktutor.in
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.
CheckoutEvent
* *
checkoutDate
dueDate
CheckoutType
dateReturned
1 * /lateCharge
finePerDay
Object Oriented Techniques SP–1 A (CS-Sem-5)
www.aktutor.in
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
Solved Paper (2012-13) SP–4 A (CS-Sem-5)
www.aktutor.in
SOLUTION OF PAPER (2012-13)
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()
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.
Solved Paper (2012-13) SP–8 A (CS-Sem-5)
www.aktutor.in
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.
(Person) (Person)
a grandmother a grandfather
Child Child
(PERSON)
Saurabh
26
<<broadcast>>
: StartUpSequencer : (Object)
registerNewEMailEvent
(urgencyThresh)
newEMailReceived
(highestUrgency)
time
open (time,
highestUrgency)
operate (playerDuration)
permitEntry
holdOpen (doorDuration)
operate
recordEntry (signDuration)
(personID, doorID,
actualTime)
time
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
Component
Component
Component dll
Component A
Realization
Interface Component A
Component A
<<interface>>
Name
Attributes
Operations
Interface name
Node1
Communication
path
Node2
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.
Object Oriented Techniques SP–1 A(CS-Sem-5)
www.aktutor.in
B. Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2013-14
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Object Oriented Techniques SP–3 A(CS-Sem-5)
www.aktutor.in
SOLUTION OF PAPER (2013-14)
Object 1 Object 2
Message C
Method 2
Method 1
Data Data
Method 1
Method 5
Method 3
Method 6
Message B
Message A
Party
location * children
0..1 parent
Person Organization
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.
Object Oriented Techniques SP–11 A(CS-Sem-5)
www.aktutor.in
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)
Object Oriented Techniques SP–1 A(CS-Sem-5)
www.aktutor.in
B. Tech.
(SEM. V) ODD SEMESTER THEORY
EXAMINATION, 2014-15
OBJECT ORIENTED TECHNIQUES
Time : 3 Hours Max. Marks : 100
Object Oriented Techniques SP–3 A(CS-Sem-5)
www.aktutor.in
SOLUTION OF PAPER (2014-15)
Node1
Communication
path
Node2
PackageName
data entry
generate
processing
output
calledPhoneHangsUp
Warning Timeout Recorded Message
onHook
timeout
Initial Pseudo State digit(n) invalidNumber
timeout
calledPhoneAnswers calledPhoneHangsUp
onHook digit(n) routed
Idle Tial Tone Dialing Connecting Ringing Connected Disconnected
valid Number
numberBusy trunkBusy
<<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.
Problem
Domain
Representation Design
Solution Domain
Representation
Object Oriented Techniques SP–1 A(CS-Sem-5)
www.aktutor.in
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
Object Oriented Techniques SP–3 A(CS-Sem-5)
www.aktutor.in
SOLUTION OF PAPER (2015-16)
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
data entry
generate
processing
output
Section-B
Programmable thermostat
Furnace relay
[temp < target temp
and season switch in Heat]
Fig. 1.
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.
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.