Connecting Tech Pros Worldwide Forums | Help | Site Map

The Interpreter Pattern in PHP 5

ltruett@fluffycat.com
Guest
 
Posts: n/a
#1: Aug 27 '06
Last week I continued my series of design patterns examples using PHP
5 with the Bridge Pattern, Flyweight Pattern, and Proxy Pattern. Here
now is my 20th PHP 5 design pattern example, the Interpreter Pattern.

http://www.fluffycat.com/PHP-Design-...s/Interpreter/

In the Interpreter Design Pattern you define a language syntax, and
parse requests that use that syntax, and call the correct classes and
methods to handle the request.

An interesting pattern, although I don't think I've used it much in
systems I've worked on. It is probably indespensible if you are
writing a compiler.


ltruett@fluffycat.com
Guest
 
Posts: n/a
#2: Aug 29 '06

re: The Interpreter Pattern in PHP 5


And now, the State Pattern.

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

In the state pattern a class will change it's behavior based on
circumstances. In my example a subclass of a specific interface may
actually switch the class being used to another subclass of the same
interface.

When I first drew up this example yesterday evening, based on one I did
a few years back in Java, I was pretty enthusiastic about it. Now, I'm
not sure I like it 100%, and may still tinker with it. I guess this
proves that these are perhaps "living examples", just my best try at an
example of a given pattern, are not set in stone, and may change. I
also have a comments section with each pattern, so please feel free to
point out flaws or applaud any examples if you like.




ltruett@fluffycat.com wrote:
Quote:
Last week I continued my series of design patterns examples using PHP
5 with the Bridge Pattern, Flyweight Pattern, and Proxy Pattern. Here
now is my 20th PHP 5 design pattern example, the Interpreter Pattern.
>
http://www.fluffycat.com/PHP-Design-...s/Interpreter/
>
In the Interpreter Design Pattern you define a language syntax, and
parse requests that use that syntax, and call the correct classes and
methods to handle the request.
>
An interesting pattern, although I don't think I've used it much in
systems I've worked on. It is probably indespensible if you are
writing a compiler.
Closed Thread