|< Day Day Up >|
We've been discussing how OOP is a revolutionary approach to developing applications. To properly understand any change of this magnitude, it is best to begin with an understanding of what is being changed. The traditional programming style, known as procedural programming, is where the change begins.
Procedural programming takes the point of view that an application is a list of instructions that are executed in a particular order and that can usually be described accurately with a flow chart.
Consider an example of an e-commerce application. In a traditional procedural system, there would be multiple routines, including the following:
In the equivalent object-oriented system, there could simply be a Product object. The Product object would be aware of its properties ( id , name , description , price , and so on), and there would be methods for interacting with it. Note that there would be only one place in the system where each task would be performed.
One such task would be the Retrieve method. This method would take an argument determining the id of the Product to retrieve, and it would return the entire object. With this method in place, any other action that might affect a Product object would use this method. Therefore, the Edit Product method could call the Retrieve Product method to get the product so that its details could be edited. Equally, the Display Product method could call the same Retrieve Product method to get the product details so that they can be shown to a customer. Even the Add Product to Cart and Ship Product methods could make use of this method. In a procedural system, changes to the way a product is shown would need to be coded in several places. In the object-oriented system described here, only code in a single place needs to be modified, without the need to give thought to how it affects the rest of the system.
A well-designed object-oriented system should closely mirror the world in which it will work. For example, the following are types of objects one might find in an e-commerce system:
In the next few chapters, we discuss the details behind determining the properties and methods of an object and how they are implemented in ActionScript 2.0.
|< Day Day Up >|