What are the advantages and disadvantages of both active record and data mapper?
Please be PHP-specific, where the language matters.
Personal experiences are welcome! Ideally with both.
What are the advantages and disadvantages of both active record and data mapper?
Please be PHP-specific, where the language matters.
Personal experiences are welcome! Ideally with both.
Active record:
advantages:
-simplicity
disadvantages:
-responsibility of storage should be a seperate responsability
-static methods are more difficult to test
-persistence often globally accessed
-active record often mistaken to be the domain object itself (example: cakephp)
Data mapper:
advantages:
-clear responsability: storing/retrieving domain objects, no mixing of concerns here
-as a result more easy to inject persistence collaborators
disadvantages:
-can be overkill on small projects that will not grow
disclaimer: I'm strongly biased in favor of the data mapper