Design Patterns used in Zend Framework [closed]

2020-05-11 21:12发布

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.

4条回答
Root(大扎)
2楼-- · 2020-05-11 21:26

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
查看更多
叛逆
3楼-- · 2020-05-11 21:29

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
查看更多
乱世女痞
4楼-- · 2020-05-11 21:35

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?

查看更多
爷、活的狠高调
5楼-- · 2020-05-11 21:39

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/

查看更多
登录 后发表回答