Object-Oriented Programming

aigle-levant · June 17, 2024

One of the most important programming paradigms in use today…

Object-oriented programming is used to design a program using classes and objects. Now let’s see what are they.

Class

A class is a blueprint for an object instantiated from it. It defines the what type of object can be created from it as well as its state and actions.

Mansion, apartment, bungalow, etc. are the instances [or objects, since they’re the same thing] of the class House with attributes such as wall-colour, roof, building materials, BHK, etc.

Object

Object is an instance of a class. A very confusing definition; let’s elaborate it further:

Object is a way by which we can introduce a class in our program and access its features.

Its state and actions performed are defined by its attributes and methods respectively.

Attributes

Attributes are information related to the object. Since their values can change and they affect an instance, we call these instance variables.

The state of an object is the value of its instance [or internal] variables at any given point of time.

Fun fact : Object and instance are the very same thing! Colour me confused…

Here’s why -> r/learnprogramming

Methods

Methods are code written inside a class that are given a name and can be called using the object [after instantiation]. They specify what an object does.

Constructor

It is a special method that creates an object from its instance variables.