Tutorials

Design Patterns - Value Object

by John Kleijn on Oct 9, 2008 7:26:24 AM

Introduction

The Value Object pattern has, just like the Singleton, to do with referencing and instances. In a way, the Value Object is the opposite of the Singleton: its goal is to ensure NOT to use the same instance, under certain conditions.

Problem

How to prevent that objects serving as containers to certain values are unintentionally reused instead of re-instantiated.

If you have read OO PHP Part 1, you probably remember Snoopy and Lassie being attached at the mouth. It is because PHP 5 uses handles instead of copying every object like PHP 4 does that the Teeth property of Lassie wasn’t duplicated, causing both dogs’ Teeth property to refer to the same Teeth object.

This is essentially what you are trying to avoid when implementing the Value Object Pattern.

Comments

No comments have been posted.
Login or register to post a comment.