Seebs wrote:
> On 2009-11-16, Marnen Laibow-Koser <marnen / marnen.org> wrote:
>>> (Note the "adjust_to" -- you can't, for obvious reasons, assign a new
>>> value with =.  Things which have stats define the attr= for those stats
>>> to use adjust_to.)
> 
>>   end
>> end
>>
>> See http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable .  Among other 
>> things, this means you never have to worry about modifying an object 
>> referred to in multiple places.
> 
> In this case, I think the correct model is that this isn't really a 
> value
> object, it's just an object which has a value.  

I think you are likely wrong.  But there's a simple conceptual test you 
can apply:

a = Stat.new(5)
b = Stat.new(5)

Should a == b return true or false?

If false, then this is probably not a value object in the conventional 
sense.

If true, then it probably is.

> Imagine that I wanted to
> talk about "my paycheck".  Well, there's a base salary, and there's 
> various
> taxes and deductions and withholding...  But except when I'm doing the 
> tax
> accounting, all I *really* care about is the take-home pay, so if I
> refer to "salary" I probably mean the output value of all those 
> calculations.

Poor analogy.  I think your paycheck is like your character's entire 
stat block, whereas the individual Stat objects seem to be analogous to 
the dollar amounts on each like of the paycheck -- and those are 
certainly value objects.

> 
> Basically, if someone else has a reference to a specific stat, and it
> changes, I think they DO want to see the now-changed value.
> 

And I think you're probably wrong.

john = Character.new
john.strength = Stat.new(15)
mary = Character.new
mary.strength = john.strength
mary.strength += 1

Now, what should john.strength be? 15 or 16?

> -s

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen / marnen.org
-- 
Posted via http://www.ruby-forum.com/.