INTRODUCTION TO OBJECT ORIENTED PROGRAMMING
Object-Oriented Programming is the most recent concept among programming paradigms and still means different things to different people. It is therefore important to have a Introduction to object oriented programming before we proceed further. Our definition of object-oriented programming is as follows:
“Object-oriented programming is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and function that can be used as templates for creating copies of such modules on demand.”
That is, an object is considered to be partitioned area of computer memory that stores data and set of operations that can access that data. Since the memory partitions are independent, the objects can be used in a variety of different programs without modifications.
Some of the striking features of object-oriented programming are:
- Emphasis is no data rather then procedure.
- Programs are divided into what are known as objects.
- Data structures are designed such that they characterize the objects.
- Functions that operate on the data of an object are tied together in the data structure.
- Data is hidden and cannot be accessed by external functions.
- Objects may communicate with each other through functions.
- New data and functions can be easily added whenever necessary.
- Follows bottom-up approach in program design.
Introduction to object oriented programming
‘Object-oriented’ remains a term, which is interpreted differently by different people. It is therefore necessary, to understand some of the concepts use extensively in object-oriented programming. We shall discuss in this section the following general concepts:
- Data abstraction
- Dynamic binding
- Data encapsulation
Objects are the basic run-time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program must handle. They may also represent user- defined data such as vectors, time and lists. Programming problem is analysed in terms of objects and the nature of communication between them. Program objects should be chosen such that they match closely with the real-world objects. As pointed out earlier, objects take up space in the memory and have an associated address like a record in Pascal, or a structure in C.
When a program is executed, the objects Interact by sending messages to one another. For example, if “customer” and “account” are two objects in a program, then the customer object may send a message to the account object requesting for the bank balance. Each object contains data and code to manipulate the data. Objects can interact without having to know details of each other’s data or code. It is sufficient to know the type of message accepted and the type of response returned by the objects.
Classes: We have mentioned the objects contain data and code to manipulate that data. The entire set of data and code of an object can be made user-defined data type with the help of a class. In fact, objects are variables of type class. Once a class has been defined, we can create any number of objects belonging to that class. Each object is associated with the data of type class with which they are created. A class is thus a collection of objects of similar type. For example, mango, apple and orange are members of the class fruit; Classes are user-defined data types and behave like the built-it type of a programming language. For example, the syntax used to create an object is no different than the syntax used to create an integer object in C.
Encapsulation: The wrapping up of data and functions into a single unit (called class) is known as encapsulation. Data encapsulation is the most striking feature of a class which 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 object’s data and the program. This insulation of the data from direct access by the program is called data hiding.
Abstraction: refers to the act of 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 such as size, weight and cost, and functions to operate on these attributes. They encapsulate all the essential properties of the objects that are to be created. Since the classes use the concept of data abstraction, they are known as abstract Data Types (ADT).
Inheritance: Creating new class by using existing class and by adding some more functionality is called inheritance. The new classes are referred as derived classes. It can inherit the data structure and functions of others. These new derived class uses existing class as building blocks which are called the base class. We can use existing class so that it can increase the reusability of the code.
The main advantages of the inheritance are:
- Reusability of the code.
- Reusability of the code.
- Transitive in nature.
This can be displayed with the help of an example Inheritance also provides the easy way to make changes. For example if some common changes are required in two wheeler and four wheeler. You can make changes in vehicle class which will be reflected automatically in both the classes.
Polymorphism: Polymorphism is another important OOP concept. Polymorphism means the ability to take more than one form. For example, an operation may exhibit different behaviour in different instances, The behaviour depends upon the types of data used in the operation For example, consider the 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 concatenations.
Polymorphism plays an important role in allowing objects having different internal structures to share the same external interface. This means that a general class of operations may be accessed in the same manner even though specific actions associated with each operation may differ. Polymorphism is extensively used in implementing inheritance.
Dynamic Binding: Binding refers to the linking of a procedure call to the code to be executed in response to the call Dynamic binding means that the code associated with a given procedure call is not know until the time of the call at runtime. It is associated with polymorphism and inheritance. A function call associated with a polymorphic reference depends on the dynamic type of the reference
Introduction to object oriented programming is important to understand before starting to learn any Programming languages because every language used the concepts to object oriented programming. So, Introduction to object oriented programming is important to learn.