Search This Blog

Monday 2 January 2017

Understanding Object and Class

The below post explains Object and Class
What is an Object?

An object represents an entity, either physical, conceptual or software.
Ø  Physical – Car or a Person
Ø  Conceptual – Chemical Process
Ø  Software – Bill Number 101, Purchase Order SO01

 An object is an entity with a well-defined boundary and identity that encapsulates its state & behaviour:
Ø  Identity - a name
Ø  State - determined by the values of its attributes
Ø  Behaviour - determined by how the object acts or reacts to requests (messages) from other objects

Object Has State

 The state of an object is one of the possible conditions in which an object may exist
 The state of an object normally changes over time
 E.g.  Rahul is an object of class Employee. The Rahul object has state:
-        Name= Rahul
-        Employee Id=123
-        Hire date=02/02/2013

Object has Behaviour

 Behaviour determines how an object acts and reacts to requests from other objects.

 The visible behaviour of an object is modelled by the set of messages it can respond to (operations the object can perform)
 Employee Rahul’s Behaviour:
-        Submit TimeSheet()
-        Complete TaskAssigned()

 The behaviour may change the state of an object.

Object has Identity

 Each object has a unique identity, even if the state is identical to that of another object.
 E.g. Employee Rahul is from XX City. Even if there is another employee with the same name – Rahul working in same city or another city they both are distinct objects

What is a Class?

 A class is a description of a set of objects that share the same attributes, operations, relationships and semantics.
Ø  An object is an instance of class

 A class is an abstraction in that it
Ø  Emphasizes relevant characteristics
Ø  Suppresses other characteristics


Relationship between Classes & Objects

Ø  A class is an abstract definition of an object.
Ø  It defines the structure & behaviour of each object in the class
Ø  It serves as a template / blue print for creating objects

Attributes of a Class

Ø  An attribute is a named property of a class that describes a range of values that instances of the property may hold
Ø  A class may have any number of attributes or no attributes at all.
Ø  An attribute has a type, which tells us what kind of attribute it is.
Ø  Typically attributes are integer, boolean, varchar etc. These are called primitive types.
Ø  Primitive types can be specific for a certain programming language.

Operations of a Class

Ø  An operation is the implementation of a service that can be requested from any object of the class to affect behaviour
Ø  A class may have any number of operations or none at all
Ø  The operations in a class describe what class can do
Ø  The operation is described with a return-type, name, zero and more parameters. This is known as signature of an operation
Often, but not always, invoking an operation on an object changes the object’s data or state 

Original Post At : http://learnerpoint.in/2017/01/02/understanding-object-and-class/

No comments:

Post a Comment