Abstract Factory and Factory Method PHP5 Design Patterns

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FluffyCat

    Abstract Factory and Factory Method PHP5 Design Patterns

    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


    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:


  • FluffyCat

    #2
    Re: Abstract Factory and Factory Method PHP5 Design Patterns

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



    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





    On Wed, 26 Oct 2005 19:39:41 -0700, FluffyCat <LTruett@Fluffy Cat.com>
    wrote:
    [color=blue]
    >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/[/color]

    Comment

    • FluffyCat

      #3
      Re: Abstract Factory and Factory Method PHP5 Design Patterns

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



      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 <LTruett@Fluffy Cat.com>
      wrote:
      [color=blue]
      >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/[/color]

      Comment

      • FluffyCat

        #4
        Re: Abstract Factory and Factory Method PHP5 Design Patterns

        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.



        [color=blue]
        > On Thu, 03 Nov 2005 14:33:57 -0800, FluffyCat <LTruett@Fluffy Cat.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 <LTruett@Fluffy Cat.com>
        >wrote:
        >[color=green]
        >>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/[/color][/color]

        Comment

        • FluffyCat

          #5
          The Facade PHP5 Design Pattern

          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.





          On Thu, 03 Nov 2005 14:33:57 -0800, FluffyCat <LTruett@Fluffy Cat.com>
          wrote:
          [color=blue]
          >...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 <LTruett@Fluffy Cat.com>
          >wrote:
          >[color=green]
          >>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/[/color][/color]

          Comment

          • Oli Filth

            #6
            Re: The Facade PHP5 Design Pattern

            FluffyCat said the following on 23/11/2005 22:40:[color=blue]
            > 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/
            >[/color]

            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

            Comment

            • FluffyCat

              #7
              Re: The Facade PHP5 Design Pattern

              On Wed, 23 Nov 2005 22:50:57 GMT, Oli Filth <catch@olifilth .co.uk>
              wrote:
              [color=blue]
              >FluffyCat said the following on 23/11/2005 22:40:[color=green]
              >> 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/
              >>[/color]
              >
              >That's not really a pattern as such, is it? It's merely an example of
              >encapsulatio n/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.[/color]


              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.

              Comment

              • A. Timurhan Cevik

                #8
                Re: The Facade PHP5 Design Pattern

                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.

                Comment

                • Yanni.Zheng

                  #9
                  Re: The Facade PHP5 Design Pattern

                  framework like cakephp?



                  Comment

                  • A. Timurhan Cevik

                    #10
                    Re: The Facade PHP5 Design Pattern

                    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.

                    Comment

                    • FluffyCat

                      #11
                      Re: The Facade PHP5 Design Pattern


                      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" <atcevik@gmail. com>
                      wrote:
                      [color=blue]
                      >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.[/color]

                      Comment

                      • FluffyCat

                        #12
                        Re: The Facade PHP5 Design Pattern

                        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" <atcevik@gmail. com>
                        wrote:
                        [color=blue]
                        >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.[/color]

                        Comment

                        Working...