9.0 Introduction


The fundamental notion of both object-oriented design and object-oriented programming is that the program is a model of an aspect of reality. The classes in the program are a summary of the reality that is being modeled ; they contain both the data and operations that can be performed on the data. The real-world objects of the implementation are represented by the objects of these classes. To quote a classic example, you might have a Vehicle class, which generically describes a transportation vehicle. It might have attributes such as number of wheels , color , brand , and so on. From this generic class, you might derive more specific classes, such as Car , Bicycle , and others. The derived classes will inherit their parent's attributes and will probably add some of their own. And, of course, the classes will most likely contain methods that operate on class data (or attributes).

The idea of grouping related ideas to create a larger entity under the umbrella of a class is often referred to as encapsulation, which is an example of information hiding. Information hiding reduces complexity because it enables programmers to focus on only the exposed methods of the class, instead of worrying about internal implementation.

Moving from the abstract idea of classes to the concrete, in PHP, classes can contain variables and functions. The variables are usually called class variables or member variables, and they hold data that is necessary for the functionality of the class, such as its attributes. The functions are called methods, and they operate on member variables or expose some other class functionality. So, if you have a class named Session that creates and saves session IDs of users, one method of the class might be a method that saves the user's session ID into a database. Another method might be a method that sets the user 's cookie. Each method builds on another to achieve the reality that is sought; in the case of the Session class, each method builds on the other to create a session management system.

PHP, although not a true object-oriented language, provides most of the functionality that is needed to package data and functions into classes, thus implementing encapsulation.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net