PHP
  Home arrow PHP arrow Combining Interfaces and Abstract Classes to Build Polymorphs in PHP
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? 
Google.com  
PHP

Combining Interfaces and Abstract Classes to Build Polymorphs in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2010-01-14


    Table of Contents:
  • Combining Interfaces and Abstract Classes to Build Polymorphs in PHP
  • Achieving Polymorphism via abstract classes
  • Defining a simple interface and an abstract class
  • Building an improved polymorph class

  • 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


    Combining Interfaces and Abstract Classes to Build Polymorphs in PHP
    (Page 1 of 4 )

    In this fifth part of a seven-part series on building polymorphs in PHP 5, you will learn how to build a polymorph object by combining an abstract class and a simple interface. As you'll see, this object will be used for constructing basic HTML divs.

    Without a doubt, understanding how to build polymorph objects in PHP 5 can be of great help when developing object-oriented web applications. this is especially true if you want to make use of the big pillars of software engineering in a truly efficient way.

    In addition, it’s quite possible that you, as a self-taught PHP developer, have already implemented Polymorphism in your own web-based programs without even knowing it. This is good; however, you should learn the theoretical concepts that surround the application of this key programming technique sooner or later in your career. This is especially true if your goal is to become a professional programmer.

    Fortunately, in the case of PHP 5, Polymorphism can be achieved in a pretty straightforward fashion, even by those who have only an intermediate background in the object-oriented paradigm and the use of interfaces.

    Naturally, if you’ve already read all of the articles that precede this one, then hopefully at this point you’ll have a solid background in how to build polymorph objects using interfaces and through abstract classes. In those tutorials I explained with a decent variety of code samples how to use Polymorphism for constructing objects that rendered some basic HTML elements, including divs and paragraphs.

    However, one thing that must be noticed with reference to these examples is that they implemented Polymorphism through either interfaces or abstract classes, but never by utilizing both approaches at the same time. So, can this be done successfully? Fortunately, the answer is yes! Moreover, the process is so easy to accomplish that it’s reduced to creating some subclasses from a base class, while making these children implementers of a certain interface. This is it.

    In the next few lines I’m going to demonstrate how to work simultaneously with interfaces and abstract classes to implement Polymorphism in PHP 5.

    Don’t waste more time and begin reading right now!



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

       

    PHP ARTICLES

    - Implementing the Iterator SPL Interface
    - Building a Data Access Layer for the Data Ma...
    - Building a Singleton Database with Restricti...
    - Working with Reflected Properties with the R...
    - The Iterator, Countable and ArrayAccess SPL ...
    - Implementing the Data Mapper Design Pattern ...
    - Defining an Abstract Class with Restrictive ...
    - The Reflection API: Working with Reflected M...
    - Using Restrictive Constructors in PHP 5
    - Getting Information on a Reflected Class wit...
    - Introducing the Reflection API in PHP 5
    - Swift Mailer's Batchsend Method and Other Fe...
    - Embedding Attachments into Email Messages wi...
    - Dynamically Attaching Files with Swift Mailer
    - Using Different Paths for Attachments with S...


    Code Analysis Tools
    Enterprise code analysis tools that deliver quality and reliable code

     



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek