SlideShare a Scribd company logo
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

More Related Content

PPTX
Functions with Heap and stack
PPTX
Sas clinical training
PDF
The Art&Science of tuning SAP HANA models
PPTX
The immutable database datomic
PPTX
3 - Trafodion Technology Look
PPTX
How Computer Cache Works
PPT
SIB Green IT Policy
PDF
BarCamp in Saigon
Functions with Heap and stack
Sas clinical training
The Art&Science of tuning SAP HANA models
The immutable database datomic
3 - Trafodion Technology Look
How Computer Cache Works
SIB Green IT Policy
BarCamp in Saigon

Viewers also liked (20)

PDF
Introduction into GIT
PPT
Client Satisfaction as engine of the continuous improvement
PPT
Soft factors - Prerequisites of Scrum
PPT
Mf Group Rev03
PDF
Dossier de prensa miradas de ciudad
PPT
Augmented Reality
PDF
Mobile Project Overview
PPT
SIB Microblogging with Yammer
PDF
Offshoring von Softwareprojekten
PDF
The Challenging Transition of Traditional Roles on the Journey to Scrum
PDF
Nota de prensa exposición "Miradas de Ciudad"
PDF
PPTX
Michaelpritchard
PDF
Wc Holiday Magazine
PPTX
Logical vectors
ODP
Improving your driveway, path or patio.
PPS
Fb Nnew Pps
PDF
Wc Magazine
Introduction into GIT
Client Satisfaction as engine of the continuous improvement
Soft factors - Prerequisites of Scrum
Mf Group Rev03
Dossier de prensa miradas de ciudad
Augmented Reality
Mobile Project Overview
SIB Microblogging with Yammer
Offshoring von Softwareprojekten
The Challenging Transition of Traditional Roles on the Journey to Scrum
Nota de prensa exposición "Miradas de Ciudad"
Michaelpritchard
Wc Holiday Magazine
Logical vectors
Improving your driveway, path or patio.
Fb Nnew Pps
Wc Magazine
Ad

Similar to An approach to implement model classes in zend (20)

PPTX
PHP Starter Application
PPT
Zend framework 03 - singleton factory data mapper caching logging
PDF
Modularity and Layered Data Model
PDF
Pursuing practices of Domain-Driven Design in PHP
KEY
Object Relational Mapping in PHP
PPT
Pursuing Domain-Driven Design practices in PHP
PDF
What is DDD and how could it help you
PDF
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
ODP
Php Site Optimization
PDF
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
PDF
DDD on example of Symfony (Webcamp Odessa 2014)
PPTX
Domain Driven Design
KEY
Data Abstraction for Large Web Applications
KEY
2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginator
PPTX
An Introduction to Domain Driven Design in PHP
PPTX
Domain Driven Design
PPT
Building Data Mapper PHP5
ODP
Introduction to Domain-Driven Design
PPT
Doctrine 2 - Introduction
PPTX
Zend Framework
PHP Starter Application
Zend framework 03 - singleton factory data mapper caching logging
Modularity and Layered Data Model
Pursuing practices of Domain-Driven Design in PHP
Object Relational Mapping in PHP
Pursuing Domain-Driven Design practices in PHP
What is DDD and how could it help you
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
Php Site Optimization
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
DDD on example of Symfony (Webcamp Odessa 2014)
Domain Driven Design
Data Abstraction for Large Web Applications
2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginator
An Introduction to Domain Driven Design in PHP
Domain Driven Design
Building Data Mapper PHP5
Introduction to Domain-Driven Design
Doctrine 2 - Introduction
Zend Framework
Ad

More from swiss IT bridge (6)

PPT
How to apply Agile in Marketing
PDF
Kooperationsmodelle im Software-Offshoring
PDF
Kundenzufriedenheit als Motor des kontinuierlichen Verbesserungsprozesses
PPT
Effective technical presentation
PDF
The Evolution of Offshoring
PDF
Software-Entwicklung im interkulturellen Kontext
How to apply Agile in Marketing
Kooperationsmodelle im Software-Offshoring
Kundenzufriedenheit als Motor des kontinuierlichen Verbesserungsprozesses
Effective technical presentation
The Evolution of Offshoring
Software-Entwicklung im interkulturellen Kontext

Recently uploaded (20)

PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
1 - Historical Antecedents, Social Consideration.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Enhancing emotion recognition model for a student engagement use case through...
Zenith AI: Advanced Artificial Intelligence
A comparative analysis of optical character recognition models for extracting...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Heart disease approach using modified random forest and particle swarm optimi...
Group 1 Presentation -Planning and Decision Making .pptx
Tartificialntelligence_presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
Accuracy of neural networks in brain wave diagnosis of schizophrenia
OMC Textile Division Presentation 2021.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)

An approach to implement model classes in zend

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

Editor's Notes

  • #3: what would you like to discuss
  • #4: what would you like to discuss
  • #5: what would you like to discuss
  • #6: what would you like to discuss
  • #7: what would you like to discuss
  • #8: what would you like to discuss
  • #9: what would you like to discuss
  • #10: what would you like to discuss
  • #11: what would you like to discuss
  • #12: what would you like to discuss
  • #13: what would you like to discuss
  • #14: what would you like to discuss
  • #15: what would you like to discuss