Value Object in ActiveRecord

Although it’s rather pretty hard to be domain driven in Rails¬†using native ActiveRecord pattern (though they say¬†it’s more the matter of rails culture and ecosystem), there are still some neat concepts, for example Value Object.

Value Object has no identity, is immutable, can be easily created and discarded. It is reusable and shareable between various entities. Actually what is it for? It simply contains attributes. It can be object like Address, Money, Point, GeoLocation, string with format limitations (ZipCode, Name), number with limitations (Percentage, Quantity, etc), etc.

You can see it in practice in docs for ActiveRecord::Aggregations. Other rereferences: The Rails3 Way, Domain Driven Design presentation, Domain Driven Design Quickly.

  1. by sobstel • February 2011