Class and Objects | SchoolingAxis

class and object


 Class and objects in OOP

Class

In object-oriented programming, a class describes a  collection of objects with similar characteristics, mutual behavior, mutual relationships to other objects and Mutual semantics (semantics means we can say that syntax). 

The class  carries the attributes and methods which will apply to objects of the class. A class defines a set of objects . A class is a modal  or standard for making comparisons for structuring and creating objects with the same attributes and methods. 

Object

An object has behavior , property, state and identity. The word object and instance are exchangeable.  Object is particularly identified by its name and it defines a state which is represented by the values of its attributes in a particular time. 

The object's state transforms because of the methods which are applied to it. These  possible sequences of state change are called the behavior of the object. The object's behavior is specified by the set of procedures which can be applied on it. Property specifies the present state of an object. 

Usually, an  object represents a single identifiable item element, or entity, either real or abstract, with a precisely defined role in the problem domain. It is possible that they present a place, a person, a bank-account , a table of data or any item that is managed by the program. 

There are four types of objects which we can represent in a program. The first three are objects with definite names, but the fourth, dynamic objects , it is not possible to recognize like this-

External objects - it is also called a global object. An external object is one which is constant (stable) and clearly visible during a program module. It also should be visible in other nodules. Objects which come under the category of 'external' would be one whose number and identities remain constant throughout an application. 

Automatic objects - alike external, global objects, we can also have a number of locally declared 'automatic' objects. Objects that are present in a  predictable nature for a certain period of time. The basic difference between an external and an automatic object is  that while an automatic object is described  within the scope of a program module, an external object is described outside of any scope. 

Static object - As we know that external objects are constant and clearly visible throughout the lifetime of a program, however automatic objects are only constant and clearly visible within the scope in which they are declared. Static object is an object which is constant from the time it is declared until the end of the program. 

Dynamic objects - Dynamic objects are controlled for their lifetime within a particular scope. 

Creating object 

In object-oriented programming, objects are generated from classes. Let's take an example, customer objects are generated from customer class. 

Difference between classes and objects

Class Object
A class is a set of objects. A single object is naturally an instance of a class.
One time we have defined a class, it exists throughout a program. Objects can be Created at run time and it also can be destroyed at run time also.
A class consists of unique names, attributes and methods. An object consists of identity, state and behavior.

One most significant factor difference between objects and classes is in the way attributes and methods are treated in objects and classes. A class is a definition about objects; the attributes and methods in a class for this reason are declarations that do not contain values. 

On the other hand, objects are created instances of a class. Each one has its own attributes and methods. The values of the set of attributes represents the condition of the objects. 

Message and method 

Objects can interact with each other by sending messages. A message is a method call from an object which is sending a message to the other object. An object which is sending is called a sender and the other object which is receiving the message from the sender object is called a receiver.

Previous Post Next Post