Introduction to object oriented programming

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.

Introduction to object oriented programming
Introduction to object oriented programming

DBMS Interview Questions and Answers 2024

Some of the striking features of object-oriented programming are:

  1. Emphasis is no data rather then procedure.
  2. Programs are divided into what are known as objects.
  3. Data structures are designed such that they characterize the objects.
  4. Functions that operate on the data of an object are tied together in the data structure.
  5. Data is hidden and cannot be accessed by external functions.
  6. Objects may communicate with each other through functions.
  7. New data and functions can be easily added whenever necessary.
  8. 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:

  1. Objects
  2. Data abstraction
  3. Inheritance
  4. Dynamic binding
  5. Classes
  6. Data encapsulation
  7. Polymorphism
  8. Classes

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.

Top Networking Interview Questions in 2024

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:

  1. Reusability of the code.
  2. Reusability of the code.
  3. 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.

3 thoughts on “Introduction to object oriented programming”

Leave a Comment