Home arrow PHP arrow User-defined interfaces in PHP 5: Implementing (X)HTML Widgets

User-defined interfaces in PHP 5: Implementing (X)HTML Widgets

In this second part of the series, you will learn the basics of object-oriented web page generation through the use of (X)HTML widgets. You will also see how objects implement the “HTMLRenderer” interface to explicitly define its functionality by using the “toHTML()” method.

  1. User-defined interfaces in PHP 5: Implementing (X)HTML Widgets
  2. Generic (X)HTML generation: defining the "HTMLRenderer" interface
  3. Working with interface implementers: defining (X)HTML widget classes
  4. Object-based (X)HTML rendering: more (X)HTML widgets to define
  5. Completing the list of (X)HTML widgets: defining classes for rendering headers and forms
By: Alejandro Gervasio
Rating: starstarstarstarstar / 7
December 26, 2005

print this article



Welcome to the second part of the series "User-defined interfaces in PHP5." By way of returning to the first article, I explained the basics for using interfaces within a PHP5 application. I also provided you with a pair of sample classes that implemented the same "DeSerializer" interface. As you surely remember, the interface's abstract methods were explicitly defined to work with byte-stream representations of data.

In addition to implementing a functional example for utilizing the sample classes, some key concepts related to interfaces were introduced as part of the tutorial. By combining the underlying theory together with the practical usage, hopefully you now understand the way in which interfaces are implemented in PHP5.

Over this second part of the series, I'll go further into the implementation of interfaces, by introducing several classes aimed specifically at generating (X)HTML "widgets" as a method of generating web pages from an object-oriented point of view. The use of independent programming structures for creating (X)HTML page objects is yet another method for building web pages focused primarily on the handled data rather than on the overall page layout used in template-based systems.

Generally, presentational widgets -- including (X)HTML widgets -- offer a greater level of flexibility for larger web programs because they allow you to define application layers in a very clear way. On top of the application, the data layer is defined (comprised of backend databases), then probably a data access layer is added (usually implemented through a persistent layer) between the databases and the core logic layer. Finally the presentational layer is set up, which receives the data and uses the widgets to generate the user interface.

The drawback to the "widget" approach resides mainly in the performance cost of creating many objects for rendering a web document, even if they only exist until the page has finished displaying.

However, and leaving out the pros and cons of presentational widgets, I'll explain a more complex usage of interfaces by associating several (X)HTML widget classes to a couple of the MySQL processing classes, in this way demonstrating how objects of different types can be "hooked up" to each other through a common shared interface, in a real application.

Having defined the goals of this second tutorial, let's get started.

>>> 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: