Object and Class

Object is at the core of Object Oriented Programming. It can be understood as a combination of attributes and behavior. The attributes are the features exhibited by objects and behavior is the set of activities the objects can do. Object and class are related in the same way Maserati is related to class car.

Attributes and Behaviors

In object oriented programming, the attributes are implemented through data and behaviors are implemented as functions or procedures. OOP paradigm of programming is totally different from other programming paradigms since here we try to emulate the real world objects in coding. The objects can be a student, a client, a bank account, insurance, a patient, a sale, a reservation etc.

A Reservation object has attributes reservation date, reservation type, amount paid, balance amount, status whether confirmed or waiting. It can exhibit behaviors like confirmation, cancellation, withdrawal or change of date or type. You can understand reservation object like a black box that can modify the attributes when the reservation object exhibits any one of the expected behaviors. It sends and receives messages though its interface implemented as a method.

object and class

In other words we can say that the object is an encapsulation of attributes and methods where the attributes are separated from behavior implemented as set of methods.  In short an object is a thing existing in real world that can perform a set of defined activities (behavior)

Advantage of Object and Class

The advantage of this kind of programming is that data is secure since it does not exist independently. It occurs only along with the methods that manipulate the data. Any other object or user does not need to understand the behavioral implementation of the object by exploring its code. Any communication needs are taken care by messages known as interface.

For the convenience of users and other objects the messages to the object are passed to the interface provided without going into its implementation details. The interface of an object consists of a set of commands dedicated to perform a task that the object is expected to do. Interface contains data that the object needs to execute a specific behavior. It also contains the information to be returned by the object after method execution.

Object and Class:: Product and Template

When objects of exactly same attributes and behaviors are grouped together as a set they can be termed as a class. Object is not a class but is a member of a class. A class is termed as a template and an object is termed as an instance of this template. Class is a blueprint that specifies how an object can be defined and how it will behave. A class once defined can be used to create multiple objects by assigning different attribute values but having same behavior.

A class declared in a program does not occupy memory. The objects instantiated from the class by assigning values to class attributes occupy the memory. When a program uses more than one objects belonging to same class, they share the class behavior (methods).