Wednesday, October 21, 2009

Chapter 7. Object-Oriented Programming and File Handling








Chapter 7. Object-Oriented Programming and File Handling


In this chapter, we're going to take a look at two important PHP topicsobject-oriented programming (OOP) and file handling. You don't absolutely need object-oriented programming to make your pages work in PHP. However, if you're going to be sticking with PHP for the long term, or if you're building substantial web applications, then OOP holds some gems for you.


OOP was first introduced to handle larger programming tasks. As we've seen, functions let you break up your programs into smaller sections, which is a great help. OOP takes the next step, letting you wrap both functions and data into objects. This lets you divide up your scripts even further because an object can contain not only a group of functions, but also the data those functions may need. For example, think of what goes on inside a refrigerator: pumps, thermostats, fans, and more are all working together. If you had to work them all by hand, it would be a disaster, but if you wrap them all into a convenient objecta refrigeratorall you must remember is that the refrigerator cools food; the details are internal.


In the same way, wrapping functions and data together lets you break up long scripts. For example, one object might handle the screen display, another might validate data, another might work with a database, and so on.









    No comments:

    Post a Comment