Object Oriented Programming Principles

Posted by Abhishek on February 25, 2020

Fundamentals

History

When programming languages were introduced into the industry, they were usually Procedural in nature. Procedural means line by line execution from top to bottom.

For example, the procedure for making a phone call is:

  1. Pick up the phone
  2. Unlock the phone
  3. Open the dialer app
  4. Type the phone number
  5. Hit the call button

In the above procedure, the steps/logic needs to be run from top to bottom (line by line) manner. You cannot make a call if you skip any steps or jump between steps randomly. This is the nature of procedural programming. To point out, programming languages like “C” are procedural in nature.

Speaking about Procedural approach, it doesn’t mean that Procedural Programming Languages are bad in any way. They are useful in terms of device programming (like the 8085/8086 Microprocessor assembly language we used to code back in college days). Just that for real world scenarios, procedural approach seems to introduce a lot of complexity.

So what is the problem with Procedural/Structural Programming Languages?

  1. Data types & Variables Every data needs to be in its own variables and you as a programmer should know what variables are created for what purpose and use it. So, a person’s first name, last name, date of birth and many other data needed to be in its own variables. There was no way of wrapping up a set of variables as the variables of a Person entity. “C” program introduced the concepts of Structs and Unions which solved the problem of wrapping up associated variables in a unit. This could only be visualized as a user defined data type. But it failed with respect to data access. Even though structs and unions were there, the data was very much accessible all over.
  2. Data Access Procedural programs didn’t have the concept of modules. Everything was methods/functions. Therefore restricting the access to data in a unit was a painful task.
  3. Responsibilities were all scattered Because everything is procedural, there was no efficient way to separate the responsibilities of a system/program in a modularized way. The only way to separate was to have separate functions. Having separate functions didn’t necessarily separate the responsibilities in a true sense.

Object Oriented perspective had to be brought

Representing a real world problem in a concise, modularized way was the need of the hour and thus Object Orientation was born. “C++” programming language brought in the first glimpse of Object Oriented Concepts and it was a huge success in the programming community.

The community started getting into C++ really deep and new object oriented programming languages like Java and .NET started to emerge .

Principles/Features of Object Orientation

  1. Class
  2. Object
  3. Encapsulation
  4. Abstraction
  5. Inheritance
  6. Polymorphism

CLASS

OBJECT

ENCAPSULATION

ABSTRACTION

INHERITANCE

POLYMORPHISM

Exercise for the Brain


Thanks for reading this post. Enjoy !!
Share on: