Specifications

$this -> DisplayHeader();
$this -> DisplayMenu($this->buttons);
echo $this->content;
$this -> DisplayFooter();
echo “</body>\n</html>\n”;
}
The function includes a few simple echo statements to display HTML, but mainly consists of
calls to other functions in the class. As you have probably guessed from their names, these
other functions display parts of the page.
It is not compulsory to break functions up like this. All these separate functions might simply
have been combined into one big function. We separated them out for a number of reasons.
Each function should have a defined task to perform. The simpler this task is, the easier writ-
ing and testing the function will be. Dont go too farif you break your program up into too
many small units, it might be hard to read.
Using inheritance, we can override operations. We can replace one large Display() function,
but it is unlikely that we will want to change the way the entire page is displayed. It will be
much better to break up the display functionality into a few self-contained tasks and be able to
override only the parts that we want to change.
Our Display function calls DisplayTitle(), DisplayKeywords(), DisplayStyles(),
DisplayHeader(), DisplayMenu(), and DisplayFooter(). This means that we need to define
these operations. One of the improvements of PHP 4 over PHP 3 is that we can write opera-
tions or functions in this logical order, calling the operation or function before the actual code
for the function. In PHP 3 and many other languages, we need to write the function or opera-
tion before it can be called.
Most of our operations are fairly simple and need to display some HTML and perhaps the con-
tents of our attributes.
Listing 6.1 shows the complete class, which we have saved as
page.inc to include or require
into other files.
LISTING 6.1 page.incOur Page Class Provides an Easy Flexible Way to Create TLA Pages
<?
class Page
{
// class Page’s attributes
var $content;
var $title = “TLA Consulting Pty Ltd”;
Object-Oriented PHP
C
HAPTER 6
6
OBJECT-ORIENTED
PHP
161
08 7842 CH06 3/6/01 3:34 PM Page 161