[ Team LiB ] Previous Section Next Section

What Is an Object?

An object is an enclosed bundle of variables and functions forged from a special template called a class. Objects hide a lot of their inner workings away from the code that uses them, providing instead easy interfaces through which you can send them orders and they can return information. These interfaces are special functions called methods. All the methods of an object have access to special variables called properties.

By defining a class, you lay down a set of characteristics. By creating objects of that type, you create entities that share these characteristics but might initialize them as different values. You might create an automobile class, for example. This class would have a color characteristic. All automobile objects would share the characteristic of color, but some would initialize it to "blue," others to "green," and so on.

Perhaps the greatest benefit of object-oriented code is its reusability. Because the classes used to create objects are self-enclosed, they can be easily pulled from one project and used in another. Additionally, it is possible to create child classes that inherit and override the characteristics of their parents. This technique can allow you to create progressively more complex and specialized objects that can draw on base functionality while adding more of their own.

Perhaps the best way to explain object-oriented programming is to do it.

    [ Team LiB ] Previous Section Next Section