News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Wojciech Sznapka:
Immutable value objects in PHP
May 16, 2014 @ 09:04:27

Wojciech Sznapka has a quick post to his site today looking at a possible implementation of Value Objects (immutable objects) in PHP applications.

Value objects are one of building blocks in Domain Driven Design. They represents a value and does not have an identity. That said, two value objects are equal if their values are equal. Other important feature is that Value Objects are immutable, i.e. they can not be modified after creation. [...] This post isn't about obvious advantages of representing domain logic with support of Value Object. As well, we wouldn't elaborate here about pros and cons of immutable objects. I'd rather would like to show an attempt to change Value Object.

His change method isn't so much a "change" as a "duplicate with new values" process. In his example he creates a EmailValueObject with "host" and "mailbox" properties. This object has a "changemailbox" method that seems to update the "mailbox" property, but in actuality clones the current object with a new "mailbox" value in the constructor.

0 comments voice your opinion now!
value object immutable clone change property

Link: http://blog.sznapka.pl/immutable-value-objects-in-php/

blog comments powered by Disqus

Similar Posts

Pádraic Brady's Blog: Complex Views with the Zend Framework - Part 4: The View Factory

Project: Aleksey Martynov's lexa-xml-serialization Tool for PHP 5.3

TechFlirt: Object Oriented Programming in PHP

Wojciech Sznapka's Blog: Why Mockery is better than PHPUnit Mock Builder (with Symfony2)

Dennis Hotson's Blog: PHP Object Oriented Programming Reinvented


Community Events





Don't see your event here?
Let us know!


zendserver unittest series interview bugfix framework community language tips opinion package laravel library deployment install symfony api podcast release introduction

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework