By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

Abstract Factory and Factory Method PHP5 Design Patterns

P: n/a
In Febraury - April of 2002 I put together in Java examples of all 23
of the classic "Gang Of Four" design patterns for my website. Partly
I wanted to get a better understanding of those patterns. They are
still online at
http://www.fluffycat.com/java/patterns.html

Since September 2003 I've mainly been using PHP, and now that PHP 5 is
becoming more available I am going to try the same thing I did in Java
with PHP.

I have only completed my pages for Abstract Factory and Factory
Method thus far and I have a pretty good idea of what I will do for
Composite and Memento. Hopefully I will be adding one or two new
patterns each week until all are complete. If any other pattern
loving PHP enthusiasts want to check it out I'd love your feedback:

http://www.fluffycat.com/SDCMSv2/
Oct 27 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Hey pattern fans, I just finished my page for the Memento Pattern
using PHP 5. You can check it out at:

http://www.FluffyCat.com/SDCMSv2/PHP...terns-Memento/

I found the whole private accessibility issue for the Memento object
was a bit of a struggle. I finally settled on having the memento
called with the originator it was getting or setting, and the memento
would only set or get the originator by calling the originator get and
sets. The downside is that I made the gets and sets on the originator
public, which may not be ideal. The friend class, which is available
in C++ is not availble in PHP, or in Java for that matter. Also not
available is Java's package level accessibility or inner classes. If
I did have to tighten up access on the originator class I might have
looked into either making the memento a child of the originator and
using protected access.

Meanwhile, if there is a nice open source UML tool anyone can
recommend for PHP I'd appreciate it. I'd also be delighted to trade
links and credit on my site for UML class diagrams with a software
company selliing a UML tool for PHP.

-Larry Truett

www.FluffyCat.com

On Wed, 26 Oct 2005 19:39:41 -0700, FluffyCat <LT*****@FluffyCat.com>
wrote:
In Febraury - April of 2002 I put together in Java examples of all 23
of the classic "Gang Of Four" design patterns for my website. Partly
I wanted to get a better understanding of those patterns. They are
still online at
http://www.fluffycat.com/java/patterns.html

Since September 2003 I've mainly been using PHP, and now that PHP 5 is
becoming more available I am going to try the same thing I did in Java
with PHP.

I have only completed my pages for Abstract Factory and Factory
Method thus far and I have a pretty good idea of what I will do for
Composite and Memento. Hopefully I will be adding one or two new
patterns each week until all are complete. If any other pattern
loving PHP enthusiasts want to check it out I'd love your feedback:

http://www.fluffycat.com/SDCMSv2/

Nov 1 '05 #2

P: n/a
....and as promised, an example of the composte pattern in PHP 5.

http://www.fluffycat.com/SDCMSv2/PHP...rns-Composite/

Much easier than the memento pattern.

I didn't do a true iterator for the Composite, partly because it
really isn't required for the Composite and partly because I will be
doing one for the Iterator pattern. I like to keep the pattern
examples as pure as I can, and adding an iterator would hav muddied
the waters somewhat.

On Wed, 26 Oct 2005 19:39:41 -0700, FluffyCat <LT*****@FluffyCat.com>
wrote:
In Febraury - April of 2002 I put together in Java examples of all 23
of the classic "Gang Of Four" design patterns for my website. Partly
I wanted to get a better understanding of those patterns. They are
still online at
http://www.fluffycat.com/java/patterns.html

Since September 2003 I've mainly been using PHP, and now that PHP 5 is
becoming more available I am going to try the same thing I did in Java
with PHP.

I have only completed my pages for Abstract Factory and Factory
Method thus far and I have a pretty good idea of what I will do for
Composite and Memento. Hopefully I will be adding one or two new
patterns each week until all are complete. If any other pattern
loving PHP enthusiasts want to check it out I'd love your feedback:

http://www.fluffycat.com/SDCMSv2/

Nov 3 '05 #3

P: n/a
Struggled to come up with at least one good example this week, almost
got something I liked for visitor and facade, but finally turned to
the decorator pattern. The decorator pattern is good to keep in mind
when you need to add functionality to a class, but changing that class
simply is not possible.

http://www.fluffycat.com/SDCMSv2/PHP...rns-Decorator/

On Thu, 03 Nov 2005 14:33:57 -0800, FluffyCat <LT*****@FluffyCat.com> wrote:

...and as promised, an example of the composte pattern in PHP 5.

http://www.fluffycat.com/SDCMSv2/PHP...rns-Composite/

Much easier than the memento pattern.

I didn't do a true iterator for the Composite, partly because it
really isn't required for the Composite and partly because I will be
doing one for the Iterator pattern. I like to keep the pattern
examples as pure as I can, and adding an iterator would hav muddied
the waters somewhat.

On Wed, 26 Oct 2005 19:39:41 -0700, FluffyCat <LT*****@FluffyCat.com>
wrote:
In Febraury - April of 2002 I put together in Java examples of all 23
of the classic "Gang Of Four" design patterns for my website. Partly
I wanted to get a better understanding of those patterns. They are
still online at
http://www.fluffycat.com/java/patterns.html

Since September 2003 I've mainly been using PHP, and now that PHP 5 is
becoming more available I am going to try the same thing I did in Java
with PHP.

I have only completed my pages for Abstract Factory and Factory
Method thus far and I have a pretty good idea of what I will do for
Composite and Memento. Hopefully I will be adding one or two new
patterns each week until all are complete. If any other pattern
loving PHP enthusiasts want to check it out I'd love your feedback:

http://www.fluffycat.com/SDCMSv2/

Nov 10 '05 #4

P: n/a
New on November 23, 2005 for www.FluffyCat.com PHP 5 Design Pattern
Examples - the Facade Pattern.

This is a pattern that most complex systems use. In the facade a
class hides a comlex susbsystem from the calling class, and also hides
the calling class from the subsystem.

My sample makes extensive use of static functions in the subsystem.
This seems to make sense if the calling class and subsystem can't be
aware of each other.

http://www.fluffycat.com/SDCMSv2/PHP...tterns-Facade/

On Thu, 03 Nov 2005 14:33:57 -0800, FluffyCat <LT*****@FluffyCat.com>
wrote:
...and as promised, an example of the composte pattern in PHP 5.

http://www.fluffycat.com/SDCMSv2/PHP...rns-Composite/

Much easier than the memento pattern.

I didn't do a true iterator for the Composite, partly because it
really isn't required for the Composite and partly because I will be
doing one for the Iterator pattern. I like to keep the pattern
examples as pure as I can, and adding an iterator would hav muddied
the waters somewhat.

On Wed, 26 Oct 2005 19:39:41 -0700, FluffyCat <LT*****@FluffyCat.com>
wrote:
In Febraury - April of 2002 I put together in Java examples of all 23
of the classic "Gang Of Four" design patterns for my website. Partly
I wanted to get a better understanding of those patterns. They are
still online at
http://www.fluffycat.com/java/patterns.html

Since September 2003 I've mainly been using PHP, and now that PHP 5 is
becoming more available I am going to try the same thing I did in Java
with PHP.

I have only completed my pages for Abstract Factory and Factory
Method thus far and I have a pretty good idea of what I will do for
Composite and Memento. Hopefully I will be adding one or two new
patterns each week until all are complete. If any other pattern
loving PHP enthusiasts want to check it out I'd love your feedback:

http://www.fluffycat.com/SDCMSv2/

Nov 23 '05 #5

P: n/a
FluffyCat said the following on 23/11/2005 22:40:
New on November 23, 2005 for www.FluffyCat.com PHP 5 Design Pattern
Examples - the Facade Pattern.

This is a pattern that most complex systems use. In the facade a
class hides a comlex susbsystem from the calling class, and also hides
the calling class from the subsystem.

My sample makes extensive use of static functions in the subsystem.
This seems to make sense if the calling class and subsystem can't be
aware of each other.

http://www.fluffycat.com/SDCMSv2/PHP...tterns-Facade/


That's not really a pattern as such, is it? It's merely an example of
encapsulation/functional abstraction. Which is one of the fundamental
underlying principles of OO design. To call this a pattern is like
saying that using a function is a pattern.

--
Oli
Nov 23 '05 #6

P: n/a
On Wed, 23 Nov 2005 22:50:57 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:
FluffyCat said the following on 23/11/2005 22:40:
New on November 23, 2005 for www.FluffyCat.com PHP 5 Design Pattern
Examples - the Facade Pattern.

This is a pattern that most complex systems use. In the facade a
class hides a comlex susbsystem from the calling class, and also hides
the calling class from the subsystem.

My sample makes extensive use of static functions in the subsystem.
This seems to make sense if the calling class and subsystem can't be
aware of each other.

http://www.fluffycat.com/SDCMSv2/PHP...tterns-Facade/


That's not really a pattern as such, is it? It's merely an example of
encapsulation/functional abstraction. Which is one of the fundamental
underlying principles of OO design. To call this a pattern is like
saying that using a function is a pattern.

Yes, I completely agree with you. The facade pattern could almost be
called the function pattern. I Ithink it may be included in most
pattern catalogs, including "Design Patterns - Elements of Reusable
Object-Oriented Software" by Gamma, Helm, Johnson and Vlissides,
because it is so prevelant in most systems. Since my intent is to
give examples in PHP 5 of the most commonly accepted patterns, and not
alter or exclude any, I added Facade to my site. It didn't hurt that
it was fairly straight forward to put an example together. I did my
example with statics partly to emphasize that it isn't the most OO of
patterns, which hopefully does capture the way previous works have
documented the facade pattern. Thanks for asking about that, as I
felt more than once while working on the Facade that while it is
certainly common and useful, it isn't as OO as say the Visitor
pattern, which I was working on at the same time.
Nov 25 '05 #7

P: n/a
Are you thinking of putting not only gof patterns but also some
enterprise level patterns such as mvc ? I think it would be great to
include some patterns such as Core J2EE patterns for php. Any study on
that ? I would like to participate, if there is.

Nov 27 '05 #8

P: n/a
framework like cakephp?

http://groups.google.com/group/cake-php?lnk=li

Nov 28 '05 #9

P: n/a
There are a lot of frameworks in php out there. I am not mentioning
building one, promoting one or helping one.

There are many architectural patterns for j2ee, there is so little info
for php. I am not talking about how to build a php framework based on
some architectural pattern documented for java, I am talking about
documenting design patterns for php, helping people to read some
patterns for php, documents that are good enough to help build
frameworks.

Some site named phppatterns (I do not remember the full adress) is
doing quite a job, but there is not any reference like java's core j2ee
patterns or dotnet patterns and designs site for php yet.

Nov 28 '05 #10

P: n/a

Yes, PHP is certainly behind Java with regard to pattern development.
This is of course partly because PHP 5 is (to me anyway) PHP's first
decent OO implementation. PHP 5 is just starting to become available
at hosting companies, so PHP programmers are just now getting into the
exciting world of OO.

On 28 Nov 2005 01:10:08 -0800, "A. Timurhan Cevik" <at*****@gmail.com>
wrote:
There are a lot of frameworks in php out there. I am not mentioning
building one, promoting one or helping one.

There are many architectural patterns for j2ee, there is so little info
for php. I am not talking about how to build a php framework based on
some architectural pattern documented for java, I am talking about
documenting design patterns for php, helping people to read some
patterns for php, documents that are good enough to help build
frameworks.

Some site named phppatterns (I do not remember the full adress) is
doing quite a job, but there is not any reference like java's core j2ee
patterns or dotnet patterns and designs site for php yet.

Nov 29 '05 #11

P: n/a
Thanks for asking, I've been wondering what I'd do after gof myself.
I'm such a huge fan of MVC that I am planning to do an example of
that.

I should add a part to the site so that others can add comments, or
even their own whole examples, but I'm still hashing out the details
of just how that would work on my site.

On 27 Nov 2005 07:56:51 -0800, "A. Timurhan Cevik" <at*****@gmail.com>
wrote:
Are you thinking of putting not only gof patterns but also some
enterprise level patterns such as mvc ? I think it would be great to
include some patterns such as Core J2EE patterns for php. Any study on
that ? I would like to participate, if there is.

Nov 29 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.