PHP
  Home arrow PHP arrow Page 2 - Building Object-Oriented Web Pages wit...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building Object-Oriented Web Pages with Inheritance in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2007-07-16

    Table of Contents:
  • Building Object-Oriented Web Pages with Inheritance in PHP 5
  • Establishing a basic class hierarchy
  • Using inheritance to derive a web page generator class
  • Building another web page for a fictional web site

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building Object-Oriented Web Pages with Inheritance in PHP 5 - Establishing a basic class hierarchy


    (Page 2 of 4 )

    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


       · In this first tutorial of the series, the concept od inheritance is applied, in...
       · Why would you not put sub-link functionality in the base class???If you know...
       · Thank you for posting your opinions with regard to my PHP article, and sorry to read...
     

       

    PHP ARTICLES

    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP
    - PHP Networking
    - Validating Web Forms with the Code Igniter P...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT