Jun 11, 2009

What does object oriented programming mean?

On our last post, we defined a program as a set of instructions that indicate the computer which tasks it should perform. This concept has changed since Object Oriented Programming (OOP) appeared in the IT world in the 1960s.
Objects, classes and methods are key to understanding object-oriented technology.Let's start by understanding objects. Look around right now and you'll find many examples of real-world objects: a dog, a desk, a person, etc. 
When you think about it, all real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming. For example, the object Peter is one particular person, with particular versions of the characteristics. The object 's state and the behavior (walking, talking, tall, etc) are defined in the object's class. The class of person defines all possible people by listing the characteristics and behaviors they can have. One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Peter object is an instance of the person class. The set of values of the attributes of a particular object is called its state.

An object-oriented program may thus be viewed as a collection of cooperating objects, as opposed to the conventional model, in which a program is seen as a list of tasks to perform. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects and can be viewed as an independent 'machine' with a distinct role or responsibility. The actions on these objects are closely associated with the object.

Now, let's talk about methods. A method can be defined as object's abilities. We can make a helpful analogy by saying that, in language, methods are verbs. Peter, being a Person, has the ability to talk. Following the example we mentioned before, talk() is one of Peter's methods. He may have other methods as well, for example sit() or type() or eat(). Within the program, using a method usually affects only one particular object; all people can talk, but you may need only one particular person to do it.

No comments:

Post a Comment