21

I am preparing talk about general architecture of Zend Framework, and wanted to summarize Design Patterns used in it.

I believe it will be beneficial both for those knowing ZF and learning DPs, and for those knowing DPs and learning ZF. In a former case, one would be able to see real-world application of patterns, and get a better comprehension of framework in the second.

Even brief answers in a form Zend_Contoller_Front: Singleton are good enough, if a little elaboration is provided (for some not-so-obvious cases) it will be even better.

I am primary interested in GoF patterns, as they seem to be the starting point of any DP-adventure.

UPD: Not directly related, but for those who know Java there's extremely complete answer for GoF's DP examples found in Java core.

Community
  • 1
  • 1
Victor Farazdagi
  • 3,080
  • 2
  • 21
  • 30
  • 1
    they sure use a lot of singleton and registry patterns i tell you that much – Hannes Nov 12 '10 at 09:58
  • 1
    So basically, you are asking us to prepare your talk? Also, you are aware that there is quite a number of patterns from POEAA in it as well, are you? MVC, TDG, RDG, FrontController, etc. ZF is basically oozing DP's. – Gordon Nov 12 '10 at 10:07
  • 1
    Why the close vote? Usage of patterns in one of the biggest PHP frameworks is not "too localized." – aib Nov 12 '10 at 10:09
  • Though I do somewhat agree with @Gordon. – aib Nov 12 '10 at 10:11
  • @aib Usage of patterns in ZF in general isn't too localized. But preparing the OP's presentation for the OP is. – Gordon Nov 12 '10 at 10:13
  • 2
    Gordon: I don't ask you to prepare my talk - I ask community to help identifying patterns, since ZF is huge project, and I definitely missed many of them. Do you really believe that talk can consist of listing components - patterns (and in question I said that even brief answers are good for me). – Victor Farazdagi Nov 12 '10 at 10:13
  • @Victor even if the question is not too localized, there is no definite answer to it. If I answer `Zend_Controller_Front` uses a `Singleton` and `FrontController` pattern and someone else says `Zend_Db_Table` uses the `Table Data Gateway` pattern and yet someone else says `Zend_Log` uses a `Factory Method` pattern to create `Adapter` and is also a `Composite`, which one will you accept? – Gordon Nov 12 '10 at 10:22
  • @Gordon: It will probably turn into community wiki, and if otherwise asked what to accept - I will accept most complete/helpful answer. Listing obvious cases might be good for the record, listing something more in-depth is definitely worth more. So, I will try to accept the answer that has, subjectively, more value in it (it doesn't correlate directly to the size of answer, but insight contained in it - as I said, ZF - is huge and I might well miss the elephant there). – Victor Farazdagi Nov 12 '10 at 10:26
  • @Gordon: btw, your comment/question about what I will choose as the correct answer, is exactly the kind of answers I was looking for: they provide directions for interested and are complete enough. – Victor Farazdagi Nov 12 '10 at 10:30
  • @Victor add `Zend_Form` as an example for `Composite` and for `Decorators`. And all the filters and validators for examples of `Strategies`. – Gordon Nov 12 '10 at 10:34
  • @Gordon Zend_Form is a good example indeed - however it is so good that it will also be an example of anti-patterns, so will undergo major refactoring for ZF2 (decorators and strategy patterns got a bit overused there). – Victor Farazdagi Nov 12 '10 at 10:37
  • @Victor maybe you could flag for moderator attention to turn the question into a CW. – Gordon Nov 12 '10 at 10:40
  • 1
    @Gordon Thanks! didn't know that I can flag post - did it now, so that moderators can decide whether it is worth turning the question into CW. – Victor Farazdagi Nov 12 '10 at 10:45
  • @Victor thanks. another option would be to go through the proposals for the various components in the ZF Wiki (currently down for me though) and check the design notes. They might contain clues too. – Gordon Nov 12 '10 at 10:55
  • 1
    Should be a *community wiki*. – takeshin Nov 12 '10 at 12:14

4 Answers4

15

Since this is a CW now, I'll add the patterns I already gave in the comments:

  • Zend_Controller_Front
    • Singleton
    • FrontController
  • Zend_Db_Table
    • Table Data Gateway
  • Zend_Log
    • Factory Method
    • Adapter
    • Composite
  • Zend_Form
    • Composite
    • Decorators
  • Zend_Filter and Zend_Validator
    • Strategy
Gordon
  • 312,688
  • 75
  • 539
  • 559
14

To name some patterns:

  • Front Controller pattern in Zend_Controller_Front (index.php + .htaccess)
  • Registry pattern in Zend_Registry
  • Dependency Injection in Zend_Application_Bootstrap_Bootstrap's container
  • Singleton (in grep getInstance)
  • Strategy patters in Zend_Form's validators
  • Decorator patterns in Zend_Form's decorators
  • Adapter pattern in | grep adapter

File and method names are obvious, so grep is your friend.

Any volunteer to edit and provide the links and sample code?

takeshin
  • 49,108
  • 32
  • 120
  • 164
1

For completeness, one should note that Zend_Form uses a modified decorator pattern. In Zend_Form, the generated content is decorated and not the object itself.

Source: http://devzone.zend.com/1240/decorators-with-zend_form/

ymas
  • 474
  • 6
  • 10
1

To provide a sample of what I want, and to help those who suspect I am asking others to do my leg-work evaluate better whether answers to this question might be helpful to someone else (either trying to learn DPs or ZF), here is sample:

Factory Method Pattern:

  • there are many cases where so called Simple Factory is used, and there's not a single place where full-fledged Factory Method Pattern is implemented (as described by GoF).
  • Examples of Simple Factory include Zend_Cache, Zend_Db, Zend_Log
Victor Farazdagi
  • 3,080
  • 2
  • 21
  • 30