• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
An approach to implement model classes in zend
 

An approach to implement model classes in zend

on

  • 1,746 views

 

Statistics

Views

Total Views
1,746
Views on SlideShare
1,746
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 An approach to implement model classes in zend Presentation Transcript

  • Quynh Le, PHP Developer swiss IT bridge gmbh www.swissITbridge.ch An approach to implement Model classes in Zend Framework
  • Agenda
      • Overview
      • Patterns
      • Reference
  • 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
  • Patterns
      • Directly inheritance from Zend_Db_Table
      • Active Record
      • Data Mapper
  • 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, ...)
  • 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, ...)
  • 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: Avoid to load the same object twice - Dependency injection: Initialize mapper objects
  • 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
  • Patterns (cont.) 3. Data Mapper (cont.) Service Layer: 
  • 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
  • Patterns (cont.) 3. Data Mapper (cont.) Sample code:
  • Reference Book: Patterns of Enterprise Application Architecture (Martin Fowler, 2002)
  •   Thank you