[This is an escerpt from the book, Microsoft AJAX Library Essentials: Client-side ASP.NET AJAX 1.0 Explained, by Cristian Darie, Bogdan Brinzarea. Published by Packt Publishing Ltd., 2007
In the next chapters you'll use this theory to work effectively with the Microsoft AJAX Library.
Concepts of Object-Oriented Programming
Objects and Classes
What does "object-oriented programming" mean anyway? Basically, as the name suggests, OOP puts objects at the cent of the programming model. The object is probably the most important concept in the world of OOPa self-contained entity that has state and behavior, just like a real-world object. Each object is an instance of a class (also called type), which defines the behavior that is shared by all its objects.
We often use objects and classes in our programs to represent real-world objects, and types (classes) of objects. For example, we can have classes like
Person, and objects such as
The concept is intuitive: the class represents the blueprint, or model, and objects are particular instances of that model. For example, all objects of type
Car will have the same behaviorfor example, the ability to change gear. However, each individual
Car object may be in a different gear at any particular timeeach object has its particular state. In programming, an object's state is described by its fields and properties, and its behavior is defined by its methods and events.
You've already worked with objects in the previous chapter. First, you've worked with the built-in documentobject. This is a default DOM object that represents the current page, and it allows you to alter the state of the page. However, you also learned how to create your own objects, when you created the
xmlHttp object. In that case,
xmlHttp is an object of the
XMLHttpRequestclass. You could create more XMLHttpRequest objects, and all of them would have the same abilities (behavior), such as the ability to contact remote servers as you learned earlier, but each would have a different state. For example, each of them may be contacting a different server.
In OOP's world everything revolves around objects and classes, and OOP languages usually offer three specific features for manipulating themencapsulation, inheritance, and polymorphism.