PHP
  Home arrow PHP arrow Page 2 - User-defined interfaces in PHP 5: Implementing (X)HTML Widgets
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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

User-defined interfaces in PHP 5: Implementing (X)HTML Widgets
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2005-12-26


    Table of Contents:
  • User-defined interfaces in PHP 5: Implementing (X)HTML Widgets
  • Generic (X)HTML generation: defining the "HTMLRenderer" interface
  • Working with interface implementers: defining (X)HTML widget classes
  • Object-based (X)HTML rendering: more (X)HTML widgets to define
  • Completing the list of (X)HTML widgets: defining classes for rendering headers and forms

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    User-defined interfaces in PHP 5: Implementing (X)HTML Widgets - Generic (X)HTML generation: defining the "HTMLRenderer" interface
    ( Page 2 of 5 )

    Object-oriented page generation may be easily done through the implementation of simple classes that render a specific (X)HTML page element. Considering this concept, elements such as tables, divs, paragraphs or forms can be conceived as conceptual objects that expose a set of properties and methods, aimed primarily at creating conjunctly the structure of a web page.

    For these objects to be functional and render the corresponding presentational structure within a web document, first I'll declare an interface called "HTMLRenderer", which exposes a single abstract method called "toHTML()". According to what you learned in the first article, this method will define the generic functionality of an object to present itself as capable of rendering (X)HTML markup.

    Certainly this capacity is mandatory on (X)HTML widget objects, so each corresponding class will implement the "HTMLRenderer" interface by using the "toHTML()" method, tasked with rendering a specific web page element. However, the interface may be implemented by other objects of different family types that are capable of delivering HTML markup in some way.

    So, considering the above concepts, I'll start by declaring the "HTMLRenderer" interface, which looks like this:

    // interface HTMLRenderer
    // defines generic method toHTML()
    interface HTMLRenderer {
        public abstract function toHTML();
    }

    As you can see, the above listed interface presents only one abstract method, "toHTML()", that defines the generic functionality of an object, which will be explicitly declared on the classes implementing the interface. As one expects, a quick look at the abstract method suggests the functionality that must be explicitly defined within each class that uses the interface.

    Having defined the simple structure of the interface, the next step is to write the (X)HTML widget classes that comprises the core logic for generating web pages, so turn your attention to the next few lines, where they will be defined.



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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT