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

Freek Lijten:
Value objects
Jul 16, 2015 @ 15:17:14

Freek Lijten has written up a post looking at value objects, how he feels they're not used enough in modern development and a few practical applications of them in action.

I would like to talk about value objects for a bit. Value objects are very underused, very powerful and general good stuff. They might not change your world but they will change, very subtle, a lot of the code you write. I hope to give the shortest possible introduction to the concept and follow up with a couple of example that make me like value objects so much.

He briefly introduces some of the basics of value objects including one of the main points: their immutability. He gives an example of working with a "10 Euro" object, pointing out that once an operation is performed using it, it becomes a different object not just one with a value changed. He also illustrates with an email address example pointing out that email addresses themselves (not the relation to the user) almost never change. He ends the post with another interesting value object scenario using IDs and making them type hint-able.

tagged: value object

Link: http://www.freeklijten.nl/home/2015/07/16/Value-objects


Trending Topics: