BASIC CONCEPTS OF OOP

oop features

Basic Concepts of Object Oriented Programming

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

OBJECTS

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. The fundamental idea behind object oriented approach is to combine both data and function into a single unit and these units are called objects.

The term objects means a combination of data and program that represent some real word entity. For example: consider an example named Mahendra; Maehdnra is 25 years old and his salary is 50000 Rs. The Mahendra may be represented in a computer program as an object. The data part of the object would be (name: Mahendra, age: 25, salary: 50000)

Class

class and object concept
class and object concept

A group of objects that share common properties for data part and some program part are collectively called as class.

As per the above image all different fruits are the objects and class for all the ‘Fruit’. In C ++ a class is a new data type that contains member variables and member functions that operate on the variables. You may categorize objects by its class or you can say it is like classification of objects into different varieties and this varieties are known as class.

Inheritance

Inheritance is the process by which one object can acquire the properties of another.Inheritance is the most promising concept of OOP, which helps realize the goal of constructing software from reusable parts, rather than hand coding every system from scratch.

Inheritance not only supports reuse across systems, but also directly facilitates extensibility within a system. Inheritance coupled with polymorphism and dynamic binding minimizes the amount of existing code to be modified while enhancing a system.

This concept describes a relationship between two (or more) types, or classes, of objects in which one is said to be a “subtype” or “child” of the other, as result the “child” object is said to inherit features of the parent, allowing for shared functionality, this lets programmers re-use or reduce code and simplifies the development and maintenance of software.

Polymorphism

Polymorphism comes from the Greek words “poly” and “morphism”. “poly” means many and “morphism” means form i.e. “many forms”.

Polymorphism means the ability to take more than one form. For example, an operation have different behavior in different instances. The behavior depends upon the type of the data used in the operation.

Polymorphism allows a single name to be reused for several related but different purposes. The purpose of polymorphism is to allow one name to be used for a general class. Depending on the type of data, a specific instance of the general case is executed.

Ex: A Same person performing different role in different situation. like a person is a student in school , passenger in public transport and patient in hospital.

Data Abstraction

Abstraction refers to the act of representing essential features without including the back ground details or explanation.

Classes use the concept of abstraction and are defined as a list of attributes such as size, weight, cost and functions to operate on these attributes. They encapsulate all essential properties of the object that are to be created. The attributes are called as data members as they hold data and the functions which operate on these data are called as member functions.

Encapsulation

Wrapping of data and functions together as a single unit is known as encapsulation.

By default data is not accessible to outside world and they are only accessible through the functions which are wrapped in a class. prevention of data direct access by the program is called data hiding or information hiding.

Related posts