Home arrow PHP arrow Page 2 - Building Object-Oriented Web Pages with Inheritance in PHP 5

Establishing a basic class hierarchy - PHP

You have probably used the principles of inheritance in any number of your object-oriented programming projects. Traditionally this means working with parent and child classes during the creation of a PHP application. In this two-part series, you'll learn a simple way to use inheritance while creating object-oriented web pages.

  1. Building Object-Oriented Web Pages with Inheritance in PHP 5
  2. Establishing a basic class hierarchy
  3. Using inheritance to derive a web page generator class
  4. Building another web page for a fictional web site
By: Alejandro Gervasio
Rating: starstarstarstarstar / 12
July 16, 2007

print this article



Since the main goal of this series is to illustrate how inheritance can be used to build an object-oriented web site, I'm going to define a base web page class, which will be tasked with setting up the blueprints for all the child objects derived from it.

This being said, the corresponding signature for this brand new web page class is listed below:

// define abstract 'WebPage' class
abstract class WebPage{
   private $html;
   private $title;
   private $mainLinks;
   private $content;
   abstract public function __construct($title,$content);
   abstract public function buildMetaData();
   abstract public function buildStyles();
   abstract public function buildHeader();
   abstract public function buildLinks();
   abstract public function buildBody();
   abstract public function buildFooter();

As shown above, the "WebPage" class has been defined as abstract, since it only establishes a generic model of how to build a simple web page. This is clearly reflected by the abstract methods declared by the class in question.

Besides, it's worthwhile to mention here that the previous base class presents a very straightforward structure for outlining the generic characteristics of a basic web document. Nonetheless, as you'll see in a few moments, all the child classes created from this parent will implement concretely all of its methods, in this way allowing the creation of a specific web page.

So far, so good right? At this point you learned how to build a base web page class, which simply behaves as an interface for generating specific web documents. Thus, considering the fact that you may want to see how a subclass derived from the previous parent "WebPage" can be provided with the required business logic to create a concrete web document, in the section to come I'm going to explain this procedure in detail.

So, want to learn how this brand new child class will be defined? Okay, click on the link below and keep reading.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: