@timriley I’ve been reading over your article again and I have a feeling that you meant to say that an
Article is an entity not a value object. From your article you quote the definition of a value object as:
A value object is one whose notion of equality is based on the values of the attributes it contains, not its object identity.
I agree with this but your article class includes an
class Article < Dry::Types::Struct attribute :id, Types::Strict::Int attribute :title, Types::Strict::String attribute :body, Types::Strict::String end
I think we both will agree that
Article.new(id: 1, title: “title”, body: “body”) != Article.new(id: 1, title: “amended title”, body: “body”) in code land but in the real world the objects are the same, they’re both referring to the exact same article (the second article is modified and therefore its title is different).
IMO a value object is something that is only identifiable by its attributes, things like money, name, address and credit cards.
I did enjoy the article though, just my 2 cents.
@coop How’s this read?
(Technically, these examples are entities rather than strict value types, because we include the record IDs in their attributes, which you'd expect to be the key indicator of equality. However, in practice,
Dry::Types::Structinstances still check for equality across all attributes, and in our apps we only ever instantiate these objects from known-good database data, which means they still behave effectively as value objects. So let's continue!)