1. Quynh Le, PHP Developer swiss IT bridge gmbh www.swissITbridge.ch An approach to implement Model classes in Zend Framework
2.
3.
4.
5.
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
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