Connecting Tech Pros Worldwide Help | Site Map

The Adapter Design Pattern in PHP 5

 
LinkBack Thread Tools Search this Thread
  #1  
Old June 27th, 2006, 10:05 PM
FluffyCat
Guest
 
Posts: n/a
Default The Adapter Design Pattern in PHP 5

Last month I continued my series of design patterns examples using PHP
5 with the Observer Pattern and the Prototype Pattern. Here now is my
16th example, the Adapter pattern.

http://www.fluffycat.com/PHP-Design-Patterns/Adapter/

In the Adapter Pattern we adapt a class we have to provide methods
another class needs, without changing the original class.

If you work with a lot of classes that you can not change, then this
pattern is certainly something you would want to consider using on a
regular basis.

  #2  
Old June 28th, 2006, 06:25 AM
Richard Levasseur
Guest
 
Posts: n/a
Default Re: The Adapter Design Pattern in PHP 5


FluffyCat wrote:[color=blue]
> Last month I continued my series of design patterns examples using PHP
> 5 with the Observer Pattern and the Prototype Pattern. Here now is my
> 16th example, the Adapter pattern.
>
> http://www.fluffycat.com/PHP-Design-Patterns/Adapter/
>
> In the Adapter Pattern we adapt a class we have to provide methods
> another class needs, without changing the original class.
>
> If you work with a lot of classes that you can not change, then this
> pattern is certainly something you would want to consider using on a
> regular basis.[/color]

Wow, thats a very nice website you have. Some very clean examples,
though a bit more explanation might be needed for some. It contains
some things that every developer should know, especially PHP ones,
since most PHP devs aren't formally taught these concepts.

For the iterator pattern you should note that there is a native
iterator interface in PHP5 (several, actually), allowing you to iterate
over arbitrary objects using foreach(). Other interfaces are available
to allow array access with [], using count(), etc etc.

Might want to note that only the most recent versions of MySQL support
the really useful SQL features, too, simply because MySQL < 4.1 is
still so common.

A short blurb or links about database normalization could be helpful,
too.

  #3  
Old June 29th, 2006, 05:55 PM
FluffyCat
Guest
 
Posts: n/a
Default Re: The Adapter Design Pattern in PHP 5

On 27 Jun 2006 23:22:38 -0700, "Richard Levasseur"
<richardlev@gmail.com> wrote:
[color=blue]
>
>FluffyCat wrote:[color=green]
>> Last month I continued my series of design patterns examples using PHP
>> 5 with the Observer Pattern and the Prototype Pattern. Here now is my
>> 16th example, the Adapter pattern.
>>
>> http://www.fluffycat.com/PHP-Design-Patterns/Adapter/
>>
>> In the Adapter Pattern we adapt a class we have to provide methods
>> another class needs, without changing the original class.
>>
>> If you work with a lot of classes that you can not change, then this
>> pattern is certainly something you would want to consider using on a
>> regular basis.[/color]
>
>Wow, thats a very nice website you have. Some very clean examples,
>though a bit more explanation might be needed for some. It contains
>some things that every developer should know, especially PHP ones,
>since most PHP devs aren't formally taught these concepts.
>
>For the iterator pattern you should note that there is a native
>iterator interface in PHP5 (several, actually), allowing you to iterate
>over arbitrary objects using foreach(). Other interfaces are available
>to allow array access with [], using count(), etc etc.
>
>Might want to note that only the most recent versions of MySQL support
>the really useful SQL features, too, simply because MySQL < 4.1 is
>still so common.
>
>A short blurb or links about database normalization could be helpful,
>too.[/color]

Thanks very much for checking out the site!

I agree with you on the thin explanations. The focus of the site is
to just give examples, but being a little more verbose would probably
help many readers.

Good point about iterators too. It's a funny pattern with most
languages already having an iterator, which is why I tried to
illustrate implementing an iterator with an algorythm that wasn't just
linearly traversing the array one element at a time.

Funny you mention db normalization, I was considering doing a series
on that once I finish the php design patterns. Probably show one
example in 1st - 4th or 5th normal form. Have to come up with good
example data for that.

-Larry Truett

LTruett@FluffyCat.com


www.FluffyCat.com

  #4  
Old June 29th, 2006, 07:55 PM
Richard Levasseur
Guest
 
Posts: n/a
Default Re: The Adapter Design Pattern in PHP 5


FluffyCat wrote:[color=blue]
> On 27 Jun 2006 23:22:38 -0700, "Richard Levasseur"
> <richardlev@gmail.com> wrote:
>[color=green]
> >
> >FluffyCat wrote:[color=darkred]
> >> Last month I continued my series of design patterns examples using PHP
> >> 5 with the Observer Pattern and the Prototype Pattern. Here now is my
> >> 16th example, the Adapter pattern.
> >>
> >> http://www.fluffycat.com/PHP-Design-Patterns/Adapter/
> >>
> >> In the Adapter Pattern we adapt a class we have to provide methods
> >> another class needs, without changing the original class.
> >>
> >> If you work with a lot of classes that you can not change, then this
> >> pattern is certainly something you would want to consider using on a
> >> regular basis.[/color]
> >
> >Wow, thats a very nice website you have. Some very clean examples,
> >though a bit more explanation might be needed for some. It contains
> >some things that every developer should know, especially PHP ones,
> >since most PHP devs aren't formally taught these concepts.
> >
> >For the iterator pattern you should note that there is a native
> >iterator interface in PHP5 (several, actually), allowing you to iterate
> >over arbitrary objects using foreach(). Other interfaces are available
> >to allow array access with [], using count(), etc etc.
> >
> >Might want to note that only the most recent versions of MySQL support
> >the really useful SQL features, too, simply because MySQL < 4.1 is
> >still so common.
> >
> >A short blurb or links about database normalization could be helpful,
> >too.[/color]
>
> Thanks very much for checking out the site!
>
> I agree with you on the thin explanations. The focus of the site is
> to just give examples, but being a little more verbose would probably
> help many readers.
>
> Good point about iterators too. It's a funny pattern with most
> languages already having an iterator, which is why I tried to
> illustrate implementing an iterator with an algorythm that wasn't just
> linearly traversing the array one element at a time.
>
> Funny you mention db normalization, I was considering doing a series
> on that once I finish the php design patterns. Probably show one
> example in 1st - 4th or 5th normal form. Have to come up with good
> example data for that.
>
> -Larry Truett
>
> LTruett@FluffyCat.com
>
>
> www.FluffyCat.com[/color]


A good example would probably be something along the Item-Supplier
common for shopping carts, or Employes-Managers-Dept-Company-etc.

This professor has some pretty good examples that you could mutiliate
for the purposes of explanation. His lecture notes also provide decent
explanation of the various normal forms.
http://www.sci.csueastbay.edu/~billard/case/

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.