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

Nicolas Bérard-Nault's Blog:
The unknown value of Value Objects
Mar 31, 2011 @ 17:12:46

Nicolas Bérard-Nault has put together a new post looking at the role that Value Objects play in application development and, more specifically, how they fit in with domain driven design (DDD). He looks to explain the unknown value of Value Objects to developers that might not know how helpful they really can be.

One of the main rules of DDD is that value objects are immutable. This is often not as self-evident as it seems, as many programmers are not even aware of the state they leak and create. Sadly, state is often positively correlated with entropy. Hence, taking steps to contain and to limit state is one of the keys to taming complexity in an application.

He notes that even outside of DDD Value Objects can be quite useful. He gives an example of a "RationalNumber" class with methods for basic things like addition and subtraction. He shows the more traditional mutable version that most developers would start with and uses it in several examples to show its flaws. He finishes up the post with a look at the "more correct" immutable version of the class and a sample call that would result in the correct output of a simple matematical operation.

tagged: valueobject domaindrivendesign mutable immutable

Link:


Trending Topics: