A Dive Into Object Oriented Programming

A few days back, one of my friends mentioned how 90 % percent of students still program in the old procedural way. And really I was shocked to notice that these stats were remarkably true.

It is unfortunate to see that majority of students jump into learning the Languages and their Syntax instead of paying attention to the basic programming concepts, therefore, leading to poor programming style and bad program designs.

Simply programming in a language that is object oriented or in a tool that does not allow procedural programming, does not accomplish OOP requirements.

Separating the tools/languages from OOP may be difficult for the beginners but not impossible.
Simply Put…

Object Oriented Programming is a way of thinking, a new thought process.

Unfortunately, most of us or rather all of us, are introduced to OOP by an introduction to new tool or language. And the emphasis is on learning the tool or language than actually grabbing the concepts of OOP.

Although learning the language is an important step, yet learning the concepts is even more vital. Learning the language before the concepts is like learning to read electric diagrams without first knowing what is electricity.

While you are on the road to OO Development, it is essential for you to learn the fundamental OO Concepts. Resist the temptation to jump directly into a language, and take the time to grasp the fundamental OO thought process.

The Object Orientation

World of OOP revolves around objects. Objects can be seen at three different levels/perspectives. These three levels are

  1. Conceptual Level
    It is the actual thought process used in designing the programs.
    It is usually not related with the software.
  2. Specification Level
    Defines how objects will be used in the software.
  3. Implementation Level
    It describes how objects will be implemented/coded in the program.

Conceptual Level of OOP

At the very conceptual level, Objects are entities or things that are aware of their state and responsible for their behaviors. We can say that Objects are things that are responsible for themselves.

Look around you. How many objects do you find?

/*******************************************************************************
Do Not Confuse Living Things or Non Living Things with Objects
Everything is object as long as it exists.
********************************************************************************/

There are lots of them, or rather all of them. Take the example of the PC you are using right now. It knows what it is, which state it is in – on or off, and it knows what it can do. Look at the fan, it knows it can rotate, get fast or slow. Objects are all around us and they are responsible for themselves.

Army and Generals

The best example of responsible objects is the Armed Forces.

Imagine a war situation where an army has to defend a country. What if the Army chief had to tell each and every general what strategy to follow, how many soldiers for a battalion and what places to protect? What if the Plan A fails, how to respond to an uncertain and unpredictable situation?

But luckily, that is not the case in reality. All the Chief has to do is instruct the Generals to protect the country.

Generals, here, are the responsible objects. They know their capabilities, strengths and are responsible for their behaviors. They know how many men are required to defend a certain piece of land and what plan to execute if the other fails.

So not only the Chief, but the country is saved too.

Specification Level of OOP

At this level, an object is a set of responsibilities that it can fulfill itself and upon the request of other objects.

Implementation Level

At the implementation, we the programmers, define how certain responsibilities shall be carried out. It is, us, that have the total control over the behavior of the objects. This is actually the coding part of OOP and this where the syntax comes handy and exactly where most students jump start from.

At this level, an object consists of data members/properties and methods also known as functions.

Properties of Objects

Objects Can Assume Roles

Objects can sometime assume different roles. They may have some characteristics in common but different in the very role that they play. You are an object, but you may assume the role of Student, Child or Teacher depending upon the context.

Also, same objects can perform different responsibilities depending upon the request.

OOP also provides a method of dealing with closely related objects in the form of Inheritance and Polymorphism discussed later in some other article.

Objects Hide their State and Actions

This property of objects is called information hiding. The technique used to hide the information about the object is called Encapsulation (Meanings: the condition of being enclosed).

As said earlier, objects are aware of their state, however, they do not need to expose this state to other objects, thus keeping their information private. Also, how an object fulfills its responsibility is totally hidden from other objects.

A PC Monitor hides all the implementation details of how it projects the images on the screen and also hides the current state of the circuits within.

Objects have an Interface

Objects have a public interface through which we can communicate with it. Continuing the example of monitor, it has a few buttons that allow us to communicate with it. We can turn it on or off, dim the brightness and do other stuff that the object can do, through its interface.

/******************************************************************
Do Not Confuse Interface Classes with this Interface
*******************************************************************/

Objects and Classes

So, objects have a predefined set of responsibilities and some data that maintains their state.

What If we need multiple objects in a program?
Do we have to define each object’s behavior separately????

Fortunately, NO. Instead of redefining objects, we create a class that contains the data members and implementation details of a particular object, say student. This class acts like a shape mold. You put liquid in it and when it hardens you get a new object while the mold remains there.

You can create a class once and then create as many objects from it as possible. Objects are said to be particular instances of Classes.

Start Thinking in Terms of Objects

Your programming skills and pleasure will increase dramatically if you have the basic understanding of the Object Oriented Programming Concepts.

OOP is a very natural way of programming and the very day you start thinking in OOP, your programming experience will become much mature and a pleasant one.

The syntax varies with the choice of languages, however, concepts remain the same. Therefore, understanding the concept helps pave way for learning new languages.

We’ve covered some of the very basic grounds of Conceptual OOP here. The Implementation and Specific Level details are covered in other articles.

….

Advertisement

About Ali Turab Gilani
BS Computer Sciences from G.C University Lahore. Served as Teaching Assistant for Programming Fundamentals... Vice President IEEE Society Student Chapter...

4 Responses to A Dive Into Object Oriented Programming

  1. Muhammad Haadi says:

    Assalam-o-Alaikum!!!

    It is awesome…
    But the thing I feel is that there should be some implemetation details as well…

    A program or just a module of it should be coded via Structural Programming n then it must be extended through Object Oriented Concepts…

    Then one can better understand the concepts…

    • tGilani says:

      Well Haadi!

      You are missing the point here…
      As I already mentioned, students jump into coding before getting the concepts right.

      And In this very article, my focus is more on concepts than their implementation..
      I’ll include some code in my next article Insha Allah…!!!

  2. Waqas Ahmed says:

    Assalam-o-Allaikum!

    Nice Article. But need to be more refined. Though it totally concentrated upon “Learning the Approach” but it depends upon the Scenario. We adapt the style according to it. It might be that we implement different styles upon different scenario and they give perfect results. But there are some situations when you can implement only one effectively.

    Eg:
    If you are said to calculate sum, it would be better to implement it in Procedural rather than OO though it can also be implemented in OO.

    But in conclusion, i must have to say that :

    ” The Article is really SUPERB ”

    Keep it UP Turab Bhai

    • tGilani says:

      Thanks For the feedback

      Things will get clearer to you in next articles…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.