Example & Tutorial understanding programming in easy ways.

What is Object Oriented Programming?

Object-Oriented Programming is a methodology or paradigm( where the program logic and data are weaved) to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts:

Object:Object means a real word entity,Any entity that has state and behavior is known as an object.
For example: chair, pen, table,bike etc. It can be physical and logical.

Class:A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior.It is a logical entity.

Inheritance:When one object invoked all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
For example:Car is a classification of Four Wheeler. Here Car acquires the properties of a four-wheeler. Other classifications could be a jeep, tempo, van etc. Four Wheeler defines a class of vehicles that have four wheels, and specific range of engine power, load carrying capacity etc. Car (termed as a sub-class) acquires these properties from Four Wheeler (termed as a super-class), and has some specific properties, which are different from other classifications of Four Wheeler, such as luxury, comfort, shape, size, usage etc.


Polymorphism:When one task is performed by different ways i.e. known as polymorphism.
For example: to convense the customer differently, to draw something e.g. shape or rectangle etc,Water shows different forms.

A car have a gear transmission system. It has four front gears and one backward gear. When the engine is accelerated then depending upon which gear is engaged different amount power and movement is delivered to the car.
In java, we use method overloading and method overriding to achieve polymorphism.

Abstraction:Hiding internal details and showing functionality is known as abstraction.
For example: phone call, we don't know the internal processing,Calculator,we don't know the internal operation etc.

In java, we use abstract class and interface to achieve abstraction.

Encapsulation:Binding the code and data together into a single unit is known as encapsulation.
For example: capsule, it is wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here
A live example of encapsulation is the class of java.util.Hashtable. User only knows that he can store data in the form of key/value pair in a Hashtable and that he can retrieve that data in the various ways. But the actual implementation like, how and where this data is actually stored, is hidden from the user. User can simply use Hashtable wherever he wants to store Key/Value pairs without bothering about its implementation.

Benefits:As follows some benefits of using object-oriented programming:

Re-usability. You can write a program using a previous developed code.
Code Sharing. You are able to standardize the way your are programming with your colleagues.
Rapid Modeling. You can prototype the classes and their interaction through a diagram.

Drawbacks:As follows the disadvantages of using object-oriented programming:

Size. Are larger than other programs, consuming more memory and disk space.
Effort. Require a lot of work to create, including the diagramming on the planning phase and the coding on the execution phase.

Read More →