Você está na página 1de 6

UNIT- 1 INTRODUCTION

Procedure Oriented Programming Programs are made up of modules, which are parts of a program that can be coded and tested separately, and then assembled to form a complete program. In procedural languages (i.e. C) these modules are procedures, where a procedure is a sequence of statements. These procedures are functions. The design method used in procedural programming is called Top Down Design. i.e, start with a problem (procedure) and then systematically break the problem down into sub problems (sub procedures). This is called functional decomposition. The primary focus is on functions.

Typical structure of procedure oriented programs

Some characteristics of Procedure Oriented Programming are :1) Emphasis is on doing things(algorithms). 2) Large programs are divided into smaller programs known as functions. 3) Most of the functions share global data. 4) Data is passed from function to function. 5) Top-down approach is used in program design. Drawbacks: 1. 2.

In a large program it is very difficult to find or identify what data is being used by which function. It does not model real world problem very well.

Object Oriented Programming (OOP) :In object oriented programming, the main modules in a program are classes, rather than procedures. The object-oriented approach allows to create classes and objects that model real world objects.

Object oriented programming allows a decomposition of a problem into number 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. However, functions of one object can access the functions of other objects.

Organization of data and functions in object oriented programming

Characteristics of Object Oriented Programming are :1) Emphasis is on data. 2) Programs are divided into objects. 3) Objects contain the data and the functions that operate on the data. 4) Data is hidden and cannot be accessed by external functions. 5) Objects may communicate with each other through functions. 6) New data and functions can be easily added whenever necessary. 7) Bottom-up approach is used in program design.

Definition of OOP
An approach resulting in modular programs by creating partitioned memory are for both data and functions, which can be used as templates for creating copies of such modules.

Basic concepts of OOP 1. Objects


Objects are the basic run-time entities in an object-oriented system. They exhibit both state and behavior The object state is shown in the form of one or more variables and the behavior is implemented using functions. They may represent a person, a place, a bank account, a table of data or any item that the program must handle. Program objects should be chosen such that they match closely with the realworld objects.

Objects take up space in the memory and have an associated address like structure in C. When a program is executed the objects interact by sending messages to one another. Representation of an object

2. Class
Objects with similar properties and methods are grouped together to form a Class. Class represents a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects become functions of the class and is referred to as Methods. Class = Storage + Behaviour

3. Data Abstraction
Abstraction refers to the act of representing essential features without including the background details. It helps in binding data and the functions together.

4. 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. This insulation of the data from direct access by the program is called data hiding or information hiding.

5. Inheritance
Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, the new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program,

6. Reusability
Once a class is created and tested and ready to use, it can be distributed to other programmers for using in their own programs. This is known as reusability.
In OOP the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it.

7. Polymorphism
Polymorphism means the ability to take more than one form. That is an operation may exhibit different behaviours in different instances. The behavior depends upon the types of data used in the operation. Example: Operation of addition. For two numbers the operation will generate a sum. If the operands are strings, then the operation would produce a third string by concatenation. The process of making an operator to exhibit different behaviours indifferent instances is known as operator overloading. Using a single function name to perform different types of tasks is known as function overloading.

8. Dynamic Binding
Binding refers to the linking of a procedure call to the code to be executed in response to the call. There are two types of binding: static binding and dynamic binding. Static binding is the binding that takes place during compilation. It is also called as early binding Dynamic binding or late binding means that the code associated with a given procedure call is not known until the time of the call at run-time Dynamic binding is associated with polymorphism and inheritance.

9. Message Communication
An object-oriented program consists of a set of objects that communicate with each other.

Object communicates with one another by sending and receiving information much the same way as people pass message to one another. Message passing involves specifying the name of the object, the name of the funciton (message) and the information to be sent.

Benefits of OOPs
1. Reusability: In OOPs programs functions and modules that are written by a user can be reused by other users without any modification. 2. Inheritance: Through this we can eliminate redundant code and extend the use of existing classes. 3. Data Hiding: The programmer can hide the data and functions in a class from other classes. It helps the programmer to build the secure programs. 4. Reduced complexity of a problem: The given problem can be viewed as a collection of different objects. Each object is responsible for a specific task. The problem is solved by interfacing the objects. This technique reduces the complexity of the program design. 5. Easy to Maintain and Upgrade: OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. 6. Message Passing: The technique of message communication between objects makes the interface with external systems easier. 7. Modifiability: it is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods;

Object-Oriented Languages
The languages should support several of the OOP concepts to claim that they are objectoriented. Depending upon the features they support, they can be classified into the following two categories:

Object-based programming languages Object-oriented programming languages Object-based programming is the style of programming that primarily supports encapsulation and object identify. Major features: * Data encapsulation * Data hiding and access mechanisms * Automatic initialization and clear-up objects * Operator overloading They do not support inheritance and dynamic binding. Object-oriented programming incorporates all of object-based programming features along with two additional features, namely, inheritance and dynamic binding. Object-based features + inheritance + dynamic binding

Applications of using OOP:


Real Time Systems Simulation and Modeling Object oriented databases AI and Expert System Neural Networks Decision support and office automation system etc.

Comparison of Procedure- Oriented Programming and Object-Oriented Programming


Procedure- Oriented Programming 1. Focus is on the functions 2. Data is not secure and can be corrupted 3. Uses top-down programming design 4. Does not model real world problems 5. Programs are divided into functions Object-Oriented Programming 1. Focus is on the data 2. Data is secure 3. Uses bottom- up programming design 4. Models real world problems 5. Programs are divided into objects

Você também pode gostar