OOSD Unit-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

UNIT-1

Explain object-oriented approach with its benefits.


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.
Describe the elements of object-oriented system.
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)
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.
Explain the major features of Object-Oriented Programming.
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. Message C Method 2 Method 1 Data Method 3 Message B Message
A Method 1 Method 5 Method 6 Data Object 1 Object 2

ii. The only way to reach the data is through these particular methods (see Fig. 1.3.1).
iii. It is the mechanism that binds together code and the data it manipulates.
iv. This concept is also used to hide the internal representation, or state, of an object from the
outside.
2. Polymorphism :
i. Polymorphism means having many forms.
ii. Polymorphism is the ability of a message to be displayed in more than one form.
iii. It plays an important role in allowing objects having different internal structure to share the
same external interface.
3. Inheritance :
i. Inheritance is the ability to create classes that share the attributes and methods of existing
classes, but with more specific features.
ii. Inheritance is mainly used for code reusability.
Describe steps of object-oriented design.
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.
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.
Differentiate between structured approach and object oriented approach.
Answer

S. Structured approach Object oriented approach


No.
1. It works with Top-down approach. It works with Bottom-up approach
2. Program is divided into number of sub- Program is organized by having number
modules or functions. of classes and objects.
3. Function call is used. Message passing is used.
4. Software reuse is not possible. Reusability is possible.
5. Structured design programming usually Object oriented design programming
left until end phases. done concurrently with other phases.
6. Structured Design is more suitable for off- It is suitable for in-house development.
shoring.
7. It shows clear transition from design to Not so clear transition from design to
implementation. implementation.
8. It is suitable for real time system, It is suitable for most business
embedded system and projects where applications, game development projects,
objects are not the most useful level of which are expected to customize or
abstraction extended
9. DFD & E-R diagram model the data. Class diagram, sequence diagram, state
chart diagram, and use cases all
contribute.
10. In this, projects can be managed easily due In this approach, projects can be difficult
to clearly identifiable phases. to manage due to uncertain transitions
between phases.

Write short notes on : Procedural v/s OOP.

S. Procedural approach Object oriented approach


No.
1. In procedural programming, program is In object-oriented programming,
divided into small parts called functions. program is divided into small parts called
objects
2. Procedural programming follows top down Object-oriented programming follows
approach. bottom up approach.
3. There is no access specifier in procedural Object-oriented programming has access
programming. specifiers like private, public, protected
etc.
4. Adding new data and function is not easy. Adding new data and function is easy.
5. Procedural programming does not have Object-oriented programming provides
any proper way for hiding data so it is less data hiding so it is more secure.
secure.
6. In procedural programming, overloading is Overloading is possible in object-
not possible. oriented programming.
7. In procedural programming, function is In object-oriented programming, data is
more important than data. more important than function.
8. Procedural programming is based on Object-oriented programming is based
unreal world. on real world.
9. Examples : C, FORTRAN, Pascal, Basic etc. Examples : C++, Java, Python, C# etc

What do you mean by object-oriented techniques ? Explain with some examples


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.
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.
What do you understand by object identity ? Explain with an example.
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.
Explain encapsulation with example.
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
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. The figure shows that attributes are hidden inside the object by a
method.

Encapsulation of an 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.
Write short note on information hiding.
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.
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
What do you mean by polymorphism ? Explain it with an example.
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
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 tradi onal and object oriented programming
environments, whereas universal polymorphism only applies to object-oriented systems.
What do you mean by modeling ? Discuss several purposes served by models with suitable
examples.
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
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.
What are the different models used in object oriented languages ?
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.
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
Write short notes on :
a. Data store
b. Actors
c. Control flow
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.
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.
What are the basic principles of modeling ? Explain in detail.
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.
Define object-oriented modeling (OOM). Describe various steps involved in OOM process.
Explain.
Answer
Object-oriented modeling :
1. Object-oriented modeling (OOM) is the construction of objects using a collection of objects
that contain stored values of the instance variables found within an object.
2. Object-oriented modeling is an approach to modeling an application that is used at the
beginning of the so ware life cycle when using an object oriented approach to so ware
development.
Steps involved in OOM process :
1. System analysis :
i. In this stage a statement of the problem is formulated and a model is build. This phase show
the important properties associated with the situation.
ii. The analysis model is a concise, precise abstraction and agreement on how the desired
system must be developed.
iii. The objective is to provide a model that can be understood by any application experts in the
area.
2. System design :
i. At this stage, the complete system architecture is designed.
ii. In this stage the whole system is divided into subsystems, based on system analysis model
and the proposed architecture of the system.
3. Object design :
i. At this stage, a design model is developed based on the analysis model.
ii. The object design decides the data structures and algorithms needed to implement each of
the classes in the system.
4. Final implementation :
i. At this stage, the final implementation of classes and relationships developed during object
design takes place.
ii. Actual implementation should be done using software engineering practice. This helps to
develop a flexible and extensible system.
Define link and association. Discuss the role of link and association in object modeling with
suitable example
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.
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

What do you mean by object modeling technique ? Explain. Discuss the various stages of the
object modeling techniques with some example.
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.
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.
What do you mean by UML ? Discuss the conceptual model of UML with the help of an
appropriate example.
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.
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. shows the conceptual model for a library system.

Describe the pros and cons of unified modeling language (UML).


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.
Why UML required ? What are the basic architecture of UML ?
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.
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.
Explain each of the following with in reference to object oriented programming style with an
example :
i. Reusability
ii. Robustness
iii. Extensibility
iv. Abstraction
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.
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.
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.
Compare Abstraction and Encapsulation.

S.No Abstraction Encapsulation


1 Abstraction is the process or Encapsulation is the process or method to contain the
method of gaining the information.
information.
2 In abstraction, problems are In encapsulation, problems are solved at the
solved at the design or interface implementation level.
level.
3 Abstraction is the method of Encapsulation is a method to hide the data in a single
hiding the unwanted information. entity or unit along with a method to protect information
from outside.
4 We can implement abstraction Encapsulation is implemented using by access modifier
using abstract class and i.e. private, protected and public.
interfaces.
5 The objects that help to perform Objects that result in encapsulation need not be
abstraction are encapsulated. abstracted.

You might also like