Quynh Le, PHP Developer swiss IT bridge gmbh www.swissITbridge.ch An approach to implement Model classes in Zend Framework
Agenda <ul><ul><li>Overview </li></ul></ul><ul><ul><li>Patterns </li></ul></ul><ul><ul><li>Reference </li></ul></ul>
Overview <ul><ul><li>- Zend Framework (ZF): MVC </li></ul></ul><ul><ul><li>- Strategy: Fat Models, Skinny Controllers </li...
Patterns <ul><ul><li>Directly inheritance from Zend_Db_Table </li></ul></ul><ul><ul><li>Active Record </li></ul></ul><ul><...
Patterns (cont.) <ul><ul><li>Directly inheritance from Zend_Db_Table   </li></ul></ul><ul><li>class Employee extends Zend_...
Patterns (cont.) 2. Active Record class Employee extends ActiveRecord {      //Storage logic methods      public function ...
Patterns (cont.) 3.  Data Mapper (Highly recommended) Separate Business logic & storage logic
Patterns (cont.) 3. Data Mapper (cont.) Patterns: - Lazy loading: Huge data fields, or relation objects - Identity map: Av...
Patterns (cont.) 3. Data Mapper (cont.) Service Layer:  - Place on the top of Domain Model and Data Mapper - Extend busine...
Patterns (cont.) 3. Data Mapper (cont.) Service Layer: 
Patterns (cont.) 3. Data Mapper (cont.) Pros: - Can handle very complex business logic - Parallel implementation - Complet...
Patterns (cont.) 3. Data Mapper (cont.) Sample code:
Reference Book: Patterns of Enterprise Application Architecture (Martin Fowler, 2002)
  Thank you
Upcoming SlideShare
Loading in...5
×

An approach to implement model classes in zend

1,649

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,649
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • what would you like to discuss
  • An approach to implement model classes in zend

    1. 1. Quynh Le, PHP Developer swiss IT bridge gmbh www.swissITbridge.ch An approach to implement Model classes in Zend Framework
    2. 2. Agenda <ul><ul><li>Overview </li></ul></ul><ul><ul><li>Patterns </li></ul></ul><ul><ul><li>Reference </li></ul></ul>
    3. 3. Overview <ul><ul><li>- Zend Framework (ZF): MVC </li></ul></ul><ul><ul><li>- Strategy: Fat Models, Skinny Controllers </li></ul></ul><ul><ul><li>- ZF does not provide guideline for Model implementation. But, it provides Zend_Db component, including: </li></ul></ul><ul><ul><ul><li> Zend_Db_Adapter </li></ul></ul></ul><ul><ul><ul><li> Zend_Db_Table </li></ul></ul></ul><ul><ul><ul><li> Zend_Db_Table_Row </li></ul></ul></ul><ul><ul><ul><li> Zend_Db_Select </li></ul></ul></ul>
    4. 4. Patterns <ul><ul><li>Directly inheritance from Zend_Db_Table </li></ul></ul><ul><ul><li>Active Record </li></ul></ul><ul><ul><li>Data Mapper </li></ul></ul>
    5. 5. Patterns (cont.) <ul><ul><li>Directly inheritance from Zend_Db_Table   </li></ul></ul><ul><li>class Employee extends Zend_Db_Table_Abstract </li></ul><ul><li>{ </li></ul><ul><li>    protected $_name = 'employees'; </li></ul><ul><li>    protected $_primary = 'id'; </li></ul><ul><li>    //Business logic methods </li></ul><ul><li>    public function calculateAge() </li></ul><ul><li>    { </li></ul><ul><li>         </li></ul><ul><li>    } </li></ul><ul><li>} </li></ul><ul><li>Pros : </li></ul><ul><li>- Simple and easy to implement </li></ul><ul><li>Cons : </li></ul><ul><li>- Hard to test without database connection </li></ul><ul><li>- Tight-coupling with Zend_Db_Table </li></ul><ul><li>- Hard to change data source (Oracle, XML, SOAP, ...) </li></ul>
    6. 6. Patterns (cont.) 2. Active Record class Employee extends ActiveRecord {     //Storage logic methods     public function insert(){}     //Business logic methods     public function calculateAge()     {      } } Pros : - Simple and easy to implement Cons : - Hard to test without database connection - Tight-coupling with Zend_Db_Table - Hard to change data source (Oracle, XML, SOAP, ...)
    7. 7. Patterns (cont.) 3. Data Mapper (Highly recommended) Separate Business logic & storage logic
    8. 8. Patterns (cont.) 3. Data Mapper (cont.) Patterns: - Lazy loading: Huge data fields, or relation objects - Identity map: Avoid to load the same object twice - Dependency injection: Initialize mapper objects
    9. 9. Patterns (cont.) 3. Data Mapper (cont.) Service Layer:  - Place on the top of Domain Model and Data Mapper - Extend business logic - Forwards calls to Domain Model or Data Mapper
    10. 10. Patterns (cont.) 3. Data Mapper (cont.) Service Layer: 
    11. 11. Patterns (cont.) 3. Data Mapper (cont.) Pros: - Can handle very complex business logic - Parallel implementation - Complete decoupling - Model is not aware of storage - Clean storage interface (implement different storages) - Can test without Database connection Cons: -  Quite much code to write
    12. 12. Patterns (cont.) 3. Data Mapper (cont.) Sample code:
    13. 13. Reference Book: Patterns of Enterprise Application Architecture (Martin Fowler, 2002)
    14. 14.   Thank you
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×