Object-Oriented Programming

Any real-world object has some properties (which may or may not change over time) and some behavior (which may or may not vary depending upon other conditions). 

e.g., A pencil is a real-world object; which has the following properties:

  • It has some color (e.g., red) (will not change with time)
  • It has some length (e.g., 10 cm) (may change when sharpening)

And it has the following behaviors:

  • It leaves a mark when appropriately used.
  • The mark may vary depending upon the pressure applied. (Depends upon an external factor)
  • Its length gets reduced when sharpened (constant behavior)

Just like this example, the real-world objects have many more features, but in programming, we cater only the required functions.

Object-oriented programming is a programming paradigm where we model real-world objects in program based objects.

Programming in OOPS has its advantages. e.g., It is easier for the programmers to relate an Object to the real world and develop code as per the expectations. Programmed objects are beneficial as and when the application scales up, adding additional features and properties is more natural. It helps in distributing responsibilities within the objective world, enabling focused thinking.

Another important feature associated with OOP (Object Oriented Programming) is the classification of objects. Since the world (real/virtual) is full of objects, it is difficult to manage them as individual objects. We need a way to classify these objects helping us relate different objects and their features. e.g., a black colored pencil. It is all the same as the one used in the previous example but is a separate object. But since they both are pencils, they belong to the same class “Pencil” . Whereas a pen, which is very similar to a pencil, belongs to a different Class. Although both Pen and Pencil are “Writing Instruments”.

This is a series of blogs which will help you understand the basics of Object-Oriented Programming. We are going to use Java as a base, but I will try to explain it in a more generic way so that the same concepts are applied in other languages as well.