On 02/16/2011 01:33 PM, Ricky Clarkson wrote:
Immutable objects can have behaviour, it's just that they'll tend to
return new versions of themselves with a change rather than mutate
themselves.
Yes, indeed I was thinking of:
public class A
{
private final B b; // injected in some way
private final Object prop2 = ... computed in some way
public Object getProp1()
{
// return something involving b;
}
public Object getProp2()
{
return prop2;
}
}
This is immutable, but it behaviour depends on b too for one of the
properties. The other is just a read-only-javabean property. For testing
it, you need to mock b. I wouldn't like seeing prop1 exposed by getter
and prop2 by final field. OF course you might argue that it's immutable
if b is immutable too, thus we could just pre-compute prop1 and assign
to a final public field. But this would change semantics (anticipating a
computation).
--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
java.net/blog/fabriziogiudici - www.tidalwave.it/people
[email protected]
--
You received this message because you are subscribed to the Google Groups "The Java
Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.