Saturday, October 27, 2007

Object oriented programming and Classes

lThink of Classes as being Template
lClasses ENCAPSULATE
–Data
–Behavior (i.e. Management of Data)
In One Location
Some More Definitions of Class


lIn Real world ,a class is a group of similar type of Objects.
lIn object oriented programming, a class is a template definition of the methods and variable in a particular kind of object.
la class is a programming language construct used to group related instance variables and methods.


lObjects are the fundamental program units of object-oriented programs.
lAn object is a specific instance of a class, it contains real values instead of variables.
lA typical object bundles together both data( also known as state) and behavior.



Object's state ::->
An object's state consists of values assigned to a set of properties within the object.
Object's behavior ::->
An object's behavior is created by a set of methods, also known as functions or routines, defined within the object.



The following diagram represents a simple Contact object .
Specifically, it contains a name and a contact type: “Smith,John”, “Business”.
The object also contains a method named DisplayInfo that outputs the values of the Name and ContactType properties.




lClass
A class is an object maker: it contains all the statements needed to create an object, its attributes, as well as the statements to describe the operations that the object will be able to perform.
lIn object-oriented programming, a class can indeed also be a member of a set of classes organized in a hierarchy. This aspect will be introduced later through the concept of inheritance. But for now, we will use the term class as just a maker of objects, or an object factory.
lHaving a class defined, you can create as many objects as needed. These objects are called instances of this class. All the instances created with a given class will have the same structure and behaviour. They will only differ regarding their state, i.e regarding the value of their attributes. Namely, names and sequences will not be the same for all sequences objects that will be created.