Home arrow PHP arrow Creating a Subclass for Building Polymorphs in PHP

Creating a Subclass for Building Polymorphs in PHP

Welcome to the fourth installment of an article series on building polymorphs in PHP. Made up of seven tutorials, this series attempts to teach you through numerous, comprehensive code samples how to create polymorph objects. You'll see how to do it using interfaces, then abstract classes, and finally a combination of both.

TABLE OF CONTENTS:
  1. Creating a Subclass for Building Polymorphs in PHP
  2. Review: building polymorph objects by using abstract classes
  3. Building another polymorph subclass
  4. The functionality of a polymorph object
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
January 13, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Now that you know what to expect from this set of articles, it’s time to summarize the topics covered in the last one. In that part of the series I started developing a basic example to demonstrate how to build a couple of polymorph classes that inherited most of their functionality from a base abstract class.

To extend this explanation, the aforementioned base class encapsulated most of the logic required for creating generic HTML elements. This made it very easy to derive a subclass from it and provide this child entity with the ability to render basic HTML divs.

Of course, it’s also fair to note that this example in its current state doesn’t clearly show how the class responsible for displaying divs on screen really behaves as a polymorph structure. However, if another child class is spawned from the corresponding parent, and it does display a different behavior when one of its methods gets called, then it’d be easy to demonstrate the polymorph nature of these classes, right?

Well, that’s exactly what I’m going to do in the next few lines For this concrete example, the brand new subclass that I plan to build next will be tasked with creating some HTML paragraphs.

Now, to learn how this will be done, click on the link below and start reading!



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap

Dev Shed Tutorial Topics: