Skip to main content

Basic concepts of object-oriented programming

It is necessary to understand some concepts used extensively in object-oriented programming.

  • Objects
  • Classes
  • Data abstraction and encapsulation
  •  Inheritance
  • Polymorphism
  • Dynamic binding
  • Message passing

Object

Objects are the basis run time entities in the object oriented system.They may represent a person, a place,a bank account and any item that program has to handle.They may also represent a user-defined data such as lists and time.Program objects should be chosen such that they match closely with the real-world objects.Object take up space in memory and have 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 other.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 ca 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.

Class

A class is a collection  of same type of objects having same attributes and common behaviours.It is just template or blueprint to create object.
Consider an example of an object you.Now you certain attributes like your age ,name,height  etc and certain behaviours like you have some style like walking,speaking.Similarly your friends Rajveer , Sukdav, Amit also certain  attributes like age,name,height etc and certain behaviours like walking,speaking.All these people represents different objects having same attributes and common behaviours.So all these objects can be grouped together a class person.
Class person
age                   (attributes)
name                (attributes)
height               (attributes)
walking()           (Functions)
speaking()         (Functions)
objects:-You(person),Rajveer(person),Sukdav(person),Amit(person)
Data Abstraction and Encapsulation
The wrapping up of data and functions into a single unit is known as encapsulation.Data encapsulation is the most striking feature if a class.The data is not accessible to the outside world,and only those functions which are wrapped in the class access it.The functions provide the interface between the objects's data and the program.This insulation of the data from direct access by the program is  called data hiding.
Abstraction is process that involves the identification essential features without knowing the internal detail of a function.Abstraction mange complexity of a program.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.
Since the classes use the concept of data abstraction,they are know as Abstract Data Types (ADT).
Inheritance
Inheritance is process of driving new class  from an existing class without modify itThis is known as derived class,Sub class,Child class.

In OPP,the concept of inheritance provides the idea of reusability.This means that we can add additional features to an existing class without modifying it.This is possible by deriving a new class from the existing class.The new class will have the combined features of the both the classes.

Polymorphism

Polymorphism is av very powerful concept that allows the designing of amazingly flexible applications.The word Polymorphism is derived from two Greek words Poly which means many and morphos which means forms.So,Polymorphism means the ability to take many forms.
Polymorphism can be defined as ability to use the same name for two or more related  but technically different tasks.In other words,Polymorphism can be defined as one interface that can be used to perform related but different tasks.For example,in C language to perform the addition of two integers or floating point numbers we need three separate functions (like sum_int(),sum_float()) for performing these two tasks.This is because C language does not support Polymorphism.But in case of C++ which supports Polymorphism,each function can be called by the same name such as sum().

Dynamic binding

Binding refer to the linking of a function call to the code of the function to be executed in response to the function call.
Binding is of two types
a) Static Binding :- In Static Binding, the linking of a function call to the code of the function to be executed in response to the function call is made at the compile time.
b) Dynamic Binding :-In Dynamic Binding, the linking of a function call to the code of the function to be executed in response to the function call is made at the run time.
Message passing
In Object Oriented Programming (OOP) different objects communicate with each other using the concept of message passing.Objects communicate with one other by sending and receiving informination much the same way as people pass messages to one another.The concept of message passing makes it easier to talk about building systems that directly model or simulate their real-world counterparts
Advantages of OOPs
  1. Data Security (Data Hinding & Abstraction)
  2. Improve Maintaiance & Modification
  3. Reusability
  4. OOPs is well suitable for Modelling Real word problem.
  5. Reduce complexity
  6. OOPs provide the facility of creating multiple objects of a class.
  7. Easy to locate and remove bugs and error.

Comments

Popular posts from this blog

Generation of Computers

Generation of Computers   – Computers were developed in different phases known as generations of computer. Depending upon the technologies used the development of electronic computers can be divided into five generations. 1.  First generation The duration lasted from 1946-1959 was based on  vacuum tubes . Because thousands of such bulbs were used, the computers were very large and generate a large amount of heat, causing many problems in temperature regulation.  Magnetic drums   were used for  memory  purpose and instruction and data was given through  punch cards . Computer were operated manually and instruction given in  machine language . E.g.   –   UNIVAC  (Universal automatic computer),  ENIAC  (Electronic Numerical Integrator And Calculator ) ,  Mark I  etc. Main Features  – 1.        Vacuum tube technology used 2.        Magnetic drums were used for storage. 3.        Supported Machine Language only 4.        They were too bulky in size, requirin

Input and Output devices

Input device Input device is a device through which data and instruction are entered into computer system. An input devices converts the data and instructions into binary form that computer can understand. This transformation is performed by “Input interface”.   The data entered through input device can be some text, some graphical image or symbol, sound etc, depending on the form of the raw data the various input devices are available. Basic Function Performed by Input unit of a computer system -   1. It accepts the instruction and data from the user. 2. It converts these instruction and data in computer acceptable form. 3. It supplies the converted instruction and data to the computer system for further processing. Some of the commonly input devices used are:- 1. Keyboard 2. Mouse 3. Joy stick 4. Track ball 5. Touch screen 6. Light Pen 7. Digitizer 8. Scanner 9. Speech Recognition Devices 1. Keyboard Keyboard is an input device for entering data a

Computer Memory

Memory :  A memory is just like a human brain. It is used to store data and instructions. Computer memory is the storage space in computer where data is to be processed and instructions required for processing are stored. The memory is divided into large number of small parts. Each part is called cell. Each location or cell has a unique address, which varies from zero to memory size minus one. The computer storage memory is measure in term of Bytes. Eight bits make one Bytes. (Measure units)   Primary Memory/Main Memory Primary memory holds only those data and instructions on which computer is currently working. Has limited capacity and data gets lost when power is switched off. It is also called main memory. It is generally made up of semiconductor device. These memories are not as fast as registers. The data and instructions required to be processed earlier reside in main memory. Characteristic of Main Memory ·           These are semiconductor memories. ·           It