Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Subtype Polymorphism - Swapping Implementation at Runtime
Sep 17, 2012 @ 17:48:52

On PHPMaster.com there's a new tutorial from Alejandro Gervasio about subtype polymorphism. It sounds a little scary, but really it's just a look at sub-objects that inherit from parents and how to swap them around at runtime to do different things.

In this article I’ll show you how to exploit the virtues that Polymorphism offers through the development of a pluggable cache component. The core functionality can be expanded later to suit your needs through the development of additional cache drivers.

He starts off with the definition of an interface to provide structure to the sample application (the CacheInterface) and implements it in two different subtypes - a FileCache and an AppCache (using the file system and APC, respectively). He builds on these and creates a "View" that uses these caching systems to generate and save the output to a cache for use later in the execution.

tagged: subtype polymorphism tutorial interface abstract caching

Link:

PHPBuilder.com:
Implementing the Singleton Pattern in PHP 5
Nov 24, 2010 @ 19:44:13

If you haven't taken much of a look at design patterns and how they can help your development life, the Singleton pattern is a good place to start. On PHPBuilder.com there's a new tutorial introducing this handy pattern and how it might fit your needs.

One of these patterns is the Singleton design pattern, which is based on the mathematical concept of a singleton (a set with a single element). [...] Sometimes the Singleton pattern can help complete important programming tasks, but only you can decide where and when it fits your needs. As a pointer, the Singleton pattern fits well when you manage a shared resource [...] because your application should have only a single instance in order to avoid conflicting requests for the same resource and to minimize performance issues.

He shows an example of how to implement it, first as a class template and then in actual use (complete with code ready to copy and paste). He also shows how you can use the singleton pattern to act as a frontend to other classes, making a sort of polymorphism simple. Thankfully, he also explains some of the risks in using this design pattern and that "less is more".

tagged: singleton designpattern tutorial polymorphism

Link:

NETTUTS.com:
Understanding and Applying Polymorphism in PHP
Sep 09, 2010 @ 16:13:37

On the NETTUTS.com site today there's a new tutorial by Steve Guidetti about understanding and handling polymorphism in PHP - making interfaces to multiple objects that all work the same way. In this tutorial he gets more in depth and includes some code to illustrate.

In object oriented programming, polymorphism is a powerful and fundamental tool. It can be used to create a more organic flow in your application. This tutorial will describe the general concept of polymorphism, and how it can easily be deployed in PHP.

He explains to concept of polymorphism for those that haven't seen it before - common interfaces to multiple objects - and how to can help make using the parts of your application much simpler. In his code examples he uses interfaces and abstract classes to make the connections. The interfaces define the structure to follow and the abstract classes are the multiple objects that must follow it.

tagged: polymorphism tutorial interface abstract class

Link:

DevShed:
Validating Incoming Data by Using Polymorphism with Objects in PHP 5
Apr 05, 2007 @ 15:56:00

DevShed has posted the final part of their look at using polymorphism with objects in PHP5, this time with a focus on validating incoming data from a form.

In this final installment of the series I'm going to show you how to develop an expandable PHP mechanism for validating different types of incoming data. This will demonstrate how this important pillar of object-oriented programming can be used with a plethora of applications.

They show how to create a simple DataValidator class to act as a base to build from. On top of this, they create classes to validate if the value is:

  • empty
  • an integer
  • if it's numeric
  • if it's in a certain range
  • if it's alphanumeric
  • if it's alphabetic
  • or if it's a valid email address
They also include how to implement these filters, showing a simple Factory pattern that creates the object and runs the value through its validation.

tagged: validation incoming data form polymorphism object php5 validation incoming data form polymorphism object php5

Link:

DevShed:
Validating Incoming Data by Using Polymorphism with Objects in PHP 5
Apr 05, 2007 @ 15:56:00

DevShed has posted the final part of their look at using polymorphism with objects in PHP5, this time with a focus on validating incoming data from a form.

In this final installment of the series I'm going to show you how to develop an expandable PHP mechanism for validating different types of incoming data. This will demonstrate how this important pillar of object-oriented programming can be used with a plethora of applications.

They show how to create a simple DataValidator class to act as a base to build from. On top of this, they create classes to validate if the value is:

  • empty
  • an integer
  • if it's numeric
  • if it's in a certain range
  • if it's alphanumeric
  • if it's alphabetic
  • or if it's a valid email address
They also include how to implement these filters, showing a simple Factory pattern that creates the object and runs the value through its validation.

tagged: validation incoming data form polymorphism object php5 validation incoming data form polymorphism object php5

Link:

DevShed:
Building Dynamic Web Pages with Polymorphism in PHP 5
Mar 28, 2007 @ 23:15:35

DevShed continues their look at using polymorphism in an application with the latest part of the series - "Building Dynamic Web Pages with Polymorphism in PHP 5".

In short, Polymorphism is a feature exposed by certain objects that belong to the same family, which eventually can behave differently, even when they're using identical methods. Or more clearly, an object can be considered polymorphic when it's capable of performing different actions by utilizing the same method.

This time they focus on web page development that uses this object-oriented practice. The create a WebPageElement that you can ID and class attributes on and use it to create HTML widgets and extend them to create Div and Link element.

tagged: php5 polymorphism dynamic pages html elements php5 polymorphism dynamic pages html elements

Link:

DevShed:
Building Dynamic Web Pages with Polymorphism in PHP 5
Mar 28, 2007 @ 23:15:35

DevShed continues their look at using polymorphism in an application with the latest part of the series - "Building Dynamic Web Pages with Polymorphism in PHP 5".

In short, Polymorphism is a feature exposed by certain objects that belong to the same family, which eventually can behave differently, even when they're using identical methods. Or more clearly, an object can be considered polymorphic when it's capable of performing different actions by utilizing the same method.

This time they focus on web page development that uses this object-oriented practice. The create a WebPageElement that you can ID and class attributes on and use it to create HTML widgets and extend them to create Div and Link element.

tagged: php5 polymorphism dynamic pages html elements php5 polymorphism dynamic pages html elements

Link:

DevShed:
Abstracting Database Access Using Polymorphism with Objects in PHP 5
Mar 21, 2007 @ 20:21:00

In a new article from DevShed, they walk you through a method of using abstraction and objects along with polymorphism to work with databases.

I'll be explaining how to implement Polymorphism to achieve a high level of abstraction when accessing different database systems. Subsequent articles will cover the use of polymorphic objects to build dynamic web documents and validate user-supplied input.

They start out with a bad example of a database link in a PHP script, a database handler that, based on what type of database you tell it you're using, handles the requests appropriately. This is good, but poor design - their alternative is using objects (created from classes of one type for each kind of database). These are pulled together in a factory class and the correct one is built - out into a generic database object that's smart enough to know what it's supposed to do.

tagged: tutorial polymorphism database access mysql sqlite abstraction layer tutorial polymorphism database access mysql sqlite abstraction layer

Link:

DevShed:
Abstracting Database Access Using Polymorphism with Objects in PHP 5
Mar 21, 2007 @ 20:21:00

In a new article from DevShed, they walk you through a method of using abstraction and objects along with polymorphism to work with databases.

I'll be explaining how to implement Polymorphism to achieve a high level of abstraction when accessing different database systems. Subsequent articles will cover the use of polymorphic objects to build dynamic web documents and validate user-supplied input.

They start out with a bad example of a database link in a PHP script, a database handler that, based on what type of database you tell it you're using, handles the requests appropriately. This is good, but poor design - their alternative is using objects (created from classes of one type for each kind of database). These are pulled together in a factory class and the correct one is built - out into a generic database object that's smart enough to know what it's supposed to do.

tagged: tutorial polymorphism database access mysql sqlite abstraction layer tutorial polymorphism database access mysql sqlite abstraction layer

Link:

DevShed:
Polymorphism, Design Patterns, and PHP Programming
Oct 05, 2006 @ 15:32:00

DevShed is continuing on with their series looking at advanced concepts of object oriented PHP with this new tutorial. It's part three of four parts, looking this time at polymorphism and design patterns in PHP.

Last week, we continued our discussion of the object-oriented features of PHP 5 by taking a first look at design patterns. This week, we will continue looking at design patterns, and examine polymorphism. This article, the third of four parts, is excerpted from chapter two of the book Advanced PHP Programming, written by George Schlossnagle.

They cover some of the more handy features OOP in PHP5, including interfaces, type hinting, the factory pattern and the singleton pattern.

tagged: tutorial polymorphism design pattern programming singleton interface factory tutorial polymorphism design pattern programming singleton interface factory

Link:


Trending Topics: