A POCKET GUIDE TO OBJECT-ORIENTED PROGRAMMING (OOP)

Classes

Many famous and some of the most popular OOP languages used a concept of Classes to distinguish between different type of Objects. That include Java, C++, C#, Kotlin, Objective-C, etc.

In real world, we often use a single word to refer or represent all objects/things of same type. For example, human, animal, bird, vehicle, etc. That’s why in OOP when we needed a way to refer to objects of same type. We introduced the concept of Classes.

So, we can say that

a class is a group, unit, representation or definition of same type of objects. Or in other words, we can say that classes are used to refer to objects of same type.

Therefore, when you want to represent humans in your program. You will create a class name Human. Similarly you can create classes for any other real life objects whenever you want to represent those in a program. You can create class Animal to represent all different animals, or Automobile class to represent all different automobiles.

You might be thinking that how can we distinguish or separate different objects from each other? How can we tell that this object is Human or Animal? There must be something that will help us differentiate one type of Objects from others. Think …

Yes. You are correct that each object has certain properties that help us in distinguishing or differentiating those from others. There are always one or more properties of each different type or class of objects that don’t exists in others. Let’s take a simple example to understand it better.

How can we differentiate all living creatures from the rest? How can we say that this object is living creature or not? One can say that if an object can breath it’s a living creature. Someone else can say that some living creatures have hairs, eyes, mouth, skin, etc. So there are always one or more properties unique to each type or class.

Similarly, humans can move, eat, sleep, think, read, speak and perform many other actions. And this list will go on and on. So there are always one or more actions as well that an object can do or perform. Sometime objects can perform these actions themselves like humans. And sometime, an object of one type can perform action on or with an object of another type. For example, we can drive a car, ride a bicycle, etc. We are a human. But, car and bicycle or different type of objects.

So we can further elaborate our definition of classes like this.

A class is a group or definition of objects of same type, that can have one or more unique properties or attributes, and they can perform action themselves or an action can be performed on or with them.

I hope you have been able to understand the basic or core concept of Classes in OOP. We will keep referring to and learning about classes throughout this course. Please click on ‘Next’ to continue.

Image placeholder

Hi! I'm Zeeshan Elahi

I have compiled and prepared this content with love for people like me and you. And as you know it always take some time and extra cups of coffee to read, compile and prepare a course or manual. If you have like reading this content and want to say thanks, please consider supporting from more stuff like this.