solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 228 forks source link

Virtus.model vs Virtus.value_object #283

Closed techthumb closed 9 years ago

techthumb commented 9 years ago

Hi,

Thanks for making this library public. We find it extremely useful.

Could you shed some light on the differences between Virtus.model and Virtus.value_object and what context should each be used in?

I've been thinking of using Virtus.value_object mainly for the equality matching. However, I wonder why that functionality is not already a part of Virtus.model.

Thanks

solnic commented 9 years ago

value object by definition needs equality methods, it also comes with private writes so you can't change a VO instance using its public methods. It is not frozen though, something I wanted to improve in virtus 2.0. This means if you need an object that is treated as an immutable value then you should use value_object not model.

Virtus models could easily get equality methods by include Equalizer.new(*attribute_set.map(&:name)) if you wanted to use this functionality.

techthumb commented 9 years ago

Got it. Thanks!