An approach to implement model classes in zend
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,034
On Slideshare
2,034
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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

Transcript

  • 1. Quynh Le, PHP Developer swiss IT bridge gmbh www.swissITbridge.ch An approach to implement Model classes in Zend Framework
  • 2. Agenda
      • Overview
      • Patterns
      • Reference
  • 3. Overview
      • - Zend Framework (ZF): MVC
      • - Strategy: Fat Models, Skinny Controllers
      • - ZF does not provide guideline for Model implementation. But, it provides Zend_Db component, including:
        •  Zend_Db_Adapter
        •  Zend_Db_Table
        •  Zend_Db_Table_Row
        •  Zend_Db_Select
  • 4. Patterns
      • Directly inheritance from Zend_Db_Table
      • Active Record
      • Data Mapper
  • 5. Patterns (cont.)
      • Directly inheritance from Zend_Db_Table  
    • class Employee extends Zend_Db_Table_Abstract
    • {
    •     protected $_name = 'employees';
    •     protected $_primary = 'id';
    •     //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, ...)
  • 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. Patterns (cont.) 3. Data Mapper (Highly recommended) Separate Business logic & storage logic
  • 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. 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. Patterns (cont.) 3. Data Mapper (cont.) Service Layer: 
  • 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. Patterns (cont.) 3. Data Mapper (cont.) Sample code:
  • 13. Reference Book: Patterns of Enterprise Application Architecture (Martin Fowler, 2002)
  • 14.   Thank you