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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

An approach to implement model classes in zend

1,578
views

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,578
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
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