DEV Community

Cover image for Class & Object Explained with Real-Life Examples
MANIKANDAN
MANIKANDAN

Posted on

Class & Object Explained with Real-Life Examples

We will discuss an important topic in object-oriented systems: classes and objects. This will not go like your teacher, I will
Say you like your friend who is teaching you.

What problems in old programming were solved by using classes and objects?

Before understanding what is class and an object are, we have to know what problem was solved at that time

Now we will see why

--> Code Repetition

  • The same logic had to be written again and again for similar entities.
  • Example: If you had 100 cars in a program, you needed a separate
    variables/functions for each.

  • If we want to change any value for any variable, we have to
    change in all places individually, when the object and class were
    not created.

CLASS

--> A class is a blueprint or template used to create objects. These
Objects represent real-world entities.
--> Class is a logical entity, which means it is just an idea or
concept
--> A concept is an idea that exists in our mind

--> example:-car(as a concept ), when we say "car", we don't
means a particular car, but the idea of a car (it has

wheels) so this is called a concept.
--> By using the class, we can create an object, by object class
getting life

Just leave every technical thing about class now, think, will you do any work without a plan, now, see this, so you want to go from your home to College, what will you do? You think a plan, at which time, bus or bike, this planning you are doing in your mind, this is class
Can only plan, not use it in real time

What is a blueprint?

A blueprint is a design or plan that shows how something should be built.

What is a template?
A template is a predefined model or pattern by using that we can use to make
many object

Example:-

Ganesh Chaturthi is coming, so we will buy a clay Ganesha statue made from a mould. The mould is the template, and the statue is the real object.

OBJECT

An object is a real-world entity made by using a class

By using a class, we can make multiple objects for that class, each
The object is unique

In the car example, the objects are different brands, like
BMW, the brand, is an object

Example:- car(class ), when we say "car", we don't
means a particular car, but the idea of a car (it has
wheels) so this is called a concept.

Every object is made by a class; without creating a class, we can not
use object

Top comments (0)