Specifications

Using PHP
P
ART I
148
This chapter explains concepts of object-oriented development and shows how they can be
implemented in PHP.
Key topics in this chapter include
Object-oriented concepts
Creating classes, attributes, and operations
Using class attributes
Calling class operations
Inheritance
Calling class methods
Designing classes
Writing the code for your class
Object-Oriented Concepts
Modern programming languages usually support or even require an object-oriented approach to
software development. Object-Oriented (OO) development attempts to use the classifications,
relationships, and properties of the objects in the system to aid in program development.
Classes and Objects
In the context of OO software, an object can be almost any item or concepta physical object
such as a desk or a customer; or a conceptual object that only exists in software, such as a text
input area or a file. Generally, we are most interested in conceptual objects including real
world objects that need to be represented in software.
Object-oriented software is designed and built as a set of self-contained objects with both
attributes and operations that interact to meet our needs. Attributes are properties or variables
that relate to the object. Operations are methods, actions, or functions that the object can per-
form to either modify itself or for some external effect.
Object-Oriented softwares central advantage is its capability to support and encourage
encapsulationalso known as data hiding. Essentially, access to the data within an object
is only available via the objects operations, known as the interface of the object.
An objects functionality is bound to the data it uses. We can easily alter the details of how the
object is implemented to improve performance, add new features, or fix bugs without having to
change the interface, which can have ripple effects throughout the project.
08 7842 CH06 3/6/01 3:34 PM Page 148