Monday, July 13, 2009

OOP

Q.5: Describe how data are shared by functions in a procedure – oriented program.
Ans: In procedure oriented program many important data items are placed as global so that they can access by all the functions. Each function may have its own local data. Global data are more vulnerable to an inadvertent change by a function.

Q.6: What is object – oriented programming? How is it different from the procedure – oriented programming?
Ans: Object – oriented programming: Object oriented programming allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects.
A type of programming in which programmers define not only the data type of a data structure but also the types of operations that can be applied to the data structure. In this way the data structure becomes an object that includes both data and functions. In addition programmers can create relationships between one object and another.
For example objects can inherit characteristics from other objects. Java, C++, Smalltalk.
Differences between OOP and POP are given bellow:
OOP POP
1. Emphasis is on data rather than procedure. 1. Emphasis is on doing things (algorithms).
2. Programs are divided into what are known as objects. 2. Large programs are divided into smaller programs known as functions.
3. Functions that operate on the data of an object are tied together in the data structure. 3. Functions transform data from one to another.
4. Data is hidden and can not be accessed by external functions. 4. Data is not hidden and can be accessed by external functions.
5. Object may communicate with each other through functions. 5. Most of the function share global data.
6. New data and functions can be easily added whenever necessary. 6. New data and functions can not add whenever necessary.
7. Follows bottom up approach in program design. 7. Employs top-down approach in program design.


Q.7: How are data and functions organized in an object – oriented program?
Ans: OOP treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the function that operate on it, and protects it from accidental modification from outside functions. OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects. The data of an object can be accessed only by the functions associated with that object.

Q.8: What are the unique advantages of an object – oriented programming paradigm?
Ans: The unique advantages of an object – oriented programming paradigm are –
i.The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.
ii.It is possible to have multiple instances of an object to co-exist without any interference.
iii.It is easy to partition the work in a project based of objects.
iv.Object oriented systems can be easily upgraded from small to large systems.
v.Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler.
vi.Software complexity can be easily managed.

Q.9: Distinguish between the following terms:
a. Object and classes
b. Data abstraction and data encapsulation
c. Inheritance and polymorphism
d. Dynamic binding and message passing
Ans:
(a) Object: Objects are the basic runtime entities in an object oriented programming. An object is an instance of a class. It can be uniquely identified by its name and it defines a state which is represented by the values of its attributes at a particular time.
The state of the object changes according to the methods which are applied to it. We refer to these possible sequences of state changes as the behavior of the object.
Class: A class is the implementation of an abstract data type (ADT). It defines attributes and methods which implement the data structure and operations of the ADT, respectively. Instances of classes are called objects. Consequently classes define properties and behaviors of sets of object. Thus a class is a collection of objects of similar type and objects are variables of the type class.

(b) Data abstraction: Abstraction refers to the act representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes.
Data encapsulation: The wrapping up of data and functions into a single unit is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. These functions provide the interface between the objects data and the program. This insulation of the data from direct access by the program is called data hiding or information hiding. As a result data become secured. Thus the encapsulation reduces complexity.

(c) Inheritance: Inheritance is the process by which objects of one class acquire the properties of objects of another class.
Inheritance is the mechanism which allows a class A to inherit properties of a class B. We say ``A inherits from B''. Objects of class A thus have access to attributes and methods of class B without the need to redefine them.
The concept of inheritance provides the idea of reusability. This means that we can add additional features to an existence class without modifying it.
Polymorphism: Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behaviors depend upon the types and number of data used in the operation. The process of making an operator exhibit different behaviors in different instances is known as operator overloading.

(d) Dynamic binding: Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding / late binding means that the code associated with a given procedure call is not known until the time of the call of the run time. It is associated with polymorphism and inheritance.
Message passing: A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of the function and the information to be sent.
Example:

Q.10: What kinds of things can become objects in OOP?
Ans: Object: Objects are the basic runtime entities in an object oriented programming. An object is an instance of a class. It can be uniquely identified by its name and it defines a state which is represented by the values of its attributes at a particular time.
The state of the object changes according to the methods which are applied to it. We refer to these possible sequences of state changes as the behavior of the object.

Q.11: Describe inheritance as applied to OOP.
Ans: Inheritance: Inheritance is the process by which objects of one class acquire the properties of objects of another class.
Inheritance is the mechanism which allows a class A to inherit properties of a class B. We say ``A inherits from B''. Objects of class A thus have access to attributes and methods of class B without the need to redefine them.
The concept of inheritance provides the idea of reusability. This means that we can add additional features to an existence class without modifying it.

No comments:

Post a Comment