A day with .Net

My day to day experince in .net

Archive for January, 2011

Object oriented basics part 1

Posted by vivekcek on January 8, 2011

My dear friends once agaian after a long time i am again started to continue my articles on programming.Sorry friends i was in some personel issues so i was unable to find time for some knowledge sharing.This time i am coming with concepts behind object oriented programming,its a series on which i will discuss about.

1.Object and Classes
2.Features of OOPS like abstarction,encapsulation with real world examples
3.Inheritence polymorphisam with real word usage

So read first part

1.What is the difference between Object oriented programming and procedure oriented programming?
Procedural programming means breaking your program into functions; where each function performs an specific task. You pass data back and forth to these functions, each function processes the data just a bit. Hence functions are the basis of the code and data plays a secondary role.So this might be called “Functions Oriented” programming, or if you will, “Procedure based” programming AKA Procedural Programming.

With Object Oriented Programming, the data has bound functions (known as “methods”) that process the data they are bound to.So you no longer pass data back and forth between functions, you just call the functions that are bound to data (albeit you still may pass parameters as extra information for these functions to perform more specific tasks).
You might call this “Data Oriented Programming”, but in OOP, the data that has bound functions is known as Object, so it is called “Object Oriented Programming”

What is Object Oriented programming?

It is a technique to think real world in terms of objects.These objects are maped into software model.

What is a class?

A class describes all the attributes of objects ,as well as the methods that implement the behaviour of member objects.A
class can be considered as the blue print or template of an object.

For example i am modeling a point(a real world mathematical point with x and y co ordinates) as a class here.

class Point
// constructor
public Point(int a, int b)
this.x = a;
this.y = b;

// member fields
public int x;
public int y;

public void MovePoint(int a, int b)
this.x = x;
this.y = y;

Friends one thing i want to say,The class has no life.its just a text of code.
The above class has 2 member fields that represent the x and y co-ordinate of a point.
The constructor of the class is invoked on creating the object of the class.
MovePoint() is a method avialble in our class to move the point across x and y co ordinates.

What is an object?

An object is the nstance of the class
ex: we can create an object of the above Point class as

Point p=new Point(10,20);

What is the difference between Object and class?

Both looks same but different,as i told earlier a class is just a blue print,but object has life,the object is the thing
that is avilble in memory on creation

Posted in Uncategorized | Leave a Comment »