Object Oriented Programming (OOP)
Object oriented programming is a programming paradigm that was developed to overcome the drawbacks and limitations of particularly procedure oriented programming. The major need for developing such languages was to manage the ever-increasing size and complexity of programs.
Characteristics of OOP
Emphasis is on data rather than procedure.
Programs are divided into objects.
Data structures are designed such that they characterize the objects.
Functions that separate 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.
Bottom-up approach is followed in program design.
Advantages of OOP:
We can eliminate redundant codes by using inheritance feature of OOP.
It is very easy for managing complex and large size problems.
The most important is the reusability of codes by using the features inheritance.
It takes very less time for the development and maintaining the software.
It is efficient for testing and implementation of the system.
It follows bottom up approach.
It can be implemented in the field of OODBMS, OOAD and different fields of engineering.
OOP has several disadvantages which made it unpopular in the early years.
Size: Object oriented programs are much larger than other programs. In the early days of computing, space on hard drives, floppy drives and in memory was at a premium. Today we do not have these restrictions.
Effort: Object oriented programs require a lot of work to create. Specifically, a great deal of planning goes into an object oriented program well before a single piece of code is ever written. Initially, this early effort was felt by many to be a waste of time. In addition, because the programs were larger (see above) coders spent more time actually writing the program.
Speed: Object oriented programs are slower than other programs, partially because of their size. Other aspects of Object Oriented Programs also demand more system resources, thus slowing the program down.
Inheritance and polymorphism important feature in OOP
The process of creating a new class form an existing class in which objects of the new class inherit the attributes and behaviors of the existing class is known as inheritance. The newly created class is called derived class or child class and the class from which new class is derived is called base class or parent class. It permits the expansion and reuse of existing code without rewriting it hence, the concept of inheritance supports the concept of reusability.
The meaning of polymorphism is having many forms. It is an important feature of OOP which refers to the ability of an object to take on different forms depending upon situations. It simplifies coding and reduces the rework involved in modifying and developing an application.
Object: An object is any entity, thing or organization that exits in real world. It consists of two fundamentals characteristics: its attributes and behaviors. For example: a dog is an object having attributes such as color, weight, age, etc. and behaviors such as barking, wagging tail, etc. In OOP, attributes are represented by data and behaviors are represented by functions.
Class: A class is the collection of similar objects. It is defined as the template or prototype to define the common attributes and behavior for all the objects of the class. The entire set of data and code of an object can be made a 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 associated with that class.
Data abstraction: In OOP, data abstraction defines the conceptual boundaries of an object. These boundaries distinguish an object from another object. So, abstraction is the act of representing essential features without including the background details. It focuses the outside view of an object, separating its essential behavior from its implementation.
Encapsulation: Encapsulation is a way if organizing data and function into a structure by concealing the way the object is implemented, that is preventing access to data by any means other than those specified. Encapsulation therefore guarantees the integrity of the data contained in the object. It implies that there is visibility to the functionalities offered by an object, and no visibility to its data.