Dictionary Definition of Objects.
- A tangible and visible entity. ie. physical objects
- Something mental or physical towards which thought, feeling or action is directed. ie conceptual objects
So examples of objects with respect to a college
Physical Objects : buildings, chairs, tables, classrooms
Conceptual Objects : course, department etc.
The definition of objects can be used to define what software object is. A software object is the idea of combining together state (data) and behaviour (operations), that when taken together represents the abstractions of realworld (physical or conceptual) objects .
What is this state and behaviour ? We will look at them right now.
State : To capture information about an object, we would require something called data eletements. Lets say that we need to capture information about an employee of an organization. We would capture information like employee name, address, sex, date of birth, department, designation, salary, educational qualifications etc. The employee name, address, sex etc are called data elements. In object oriented terminology, these data elements are called attributes. This attributes are called as fields in .NET. These attribute values when taken together determines state or condition of the object. For example, if we want to determine if an employee is eligible for promotion, we need to look a the employees current designation, educational qualifications etc.
Behaviour : In object oriented terminology, behaviour is something (action) an object does to access the attributes and to modify/maintain the attribute. For example, to know the salary of the employee, the ojbect need to access its salary attribute. When an attribute value is changed, it means that the objects state is changed. For example, if we change the value of designation attribute to manager, then the state of employee is changed from current state. Behaviour can also be servicing a request. For example a department object shall ask all the employee object the salary.
In C# terminology, the behaviour is called as method
What are Classes?
A class is an abstraction describing of common features of all objects in a group of similar objects. For example, a class called Employee describes the Employee object.
The class describes the following about an object
- Attributes and their datatypes
- The methods
An object can do only the t hings (methods) that are defined in the class. Similary, an object can only set and access the attributes defined in the class.
Classes can also be viewed as Templates from which an oject is created. Some even call class as user defined datatype (I am not sure if I will call it like that).
From a class we can create many objects. The process of creating an object from a class is called as Instantiating. Since objects are created from a class, objects are also called as Instance of a particular class
Difference between Class and Object
Classes define the attributes and methods. Classes can be thought as templates
Object is an instance of a class with required attributes filled in with values
Encapsulation is the formal term given in Object terminology to mechanisim of bundling attributes and methods together.
Composition is the technique of having attribute as reference variable. That is, an attribute with in a class can hold reference to antoher object. We normally do this in our class design. But we dont know what OO calls it. I am mentioning it here so that I remember it in future as well 🙂