Re: Re: difference between value objects and dto
Justin Daubenmire <jdaubenm <at> yahoo.com>
2008-11-03 23:06:56 GMT
Thanks guys for the clarification... it now has "clicked"!
Regards,
Justin
----- Original Message -----
From: "jasonmeckley" <jasonmeckley <at> gmail.com>
To: <domaindrivendesign <at> yahoogroups.com>
Sent: Monday, November 03, 2008 4:58 PM
Subject: [domaindrivendesign] Re: difference between value objects and dto
> to expand (or simplify?) what Greg said.
> Value objects usually contain smarts (logic). with the money example
> you could use a simple float type like
> Float money = 1.20;
>
> any logic performed on that will be exposed to whatever object uses
> it. A value object of money would encapsulate that logic to ensure it
> is always used correctly.
>
> Money money = new Money(120);
> Money newValue = money.Add(new Money(300));
> or
> Money euro = new Money(120, Currency.UsDollar).ExchangeTo(Currency.Euro);
>
> DTO do not contain logic. they pass values from one layer to the next.
> this is common with messaging and presentation.
>
> --- In domaindrivendesign <at> yahoogroups.com, "Greg Young"
> <gregoryyoung1@...> wrote:
>>
>> immutability is a property they both tend to share but they have very
>> different intents.
>>
>> Value objects are used to abstract a concept
>> DTOs are used to transfer data between layers or tiers
>>
>> Example: I would use a money object to abstract and represent the
>> concept of *money* in my system. One benefit of doing this is that I
>> can insure validty of the data inside (imagine that my concept of
>> "Money" does not allow for a negative value or for fractional pennies
>> my Money value object can insure these invariants).
>>
>> DTOs on the other hand are generally used as thin object to pass data
>> between layers or tiers.
>>
>> Cheers,
>>
>> Greg
>>
>> On Mon, Nov 3, 2008 at 12:31 PM, Justin Daubenmire <jdaubenm@...> wrote:
>> > All,
>> >
>> > I recently came across a project that was using ddd and I seen
> value objects
>> > and data transfer objects (dtos) in the project. My question is
> this, what
>> > is the difference between value objects and dtos? Aren't they
> really the
>> > same thing? value objects are non-mutable and so are dto objects.
>> >
>> > Thanks for any clarification!
>> >
>> > Justin
>> >
>> >
>>
>>
>>
>> --
>> It is the mark of an educated mind to be able to entertain a thought
>> without accepting it.
>>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
------------------------------------