On Mon, Oct 5, 2009 at 12:26 PM, Rickard Öberg <[email protected]> wrote:
> Hi,
>
> In StreamFlow we noticed a need for immutable QueryBuilders, so that each
> where() call would create a new builder. Basically, we wanted to create a
> base builder with a where()-clause, and then be able to build upon that base
> many times.
>
> There would be basically two ways to support it: either make QueryBuilder
> clonable or make it immutable. I chose to make it immutable, which means
> that what is returned from the QueryBuilder.where() call is not the builder
> itself but rather a new QueryBuilder with the new where() clause added.
>
> I have updated the tests that relied on QB being mutable.

So, all query building methods would need to return query builders.

Again, in principle I am all for Immutable objects, as this simplifies
thread handling and other concurrency issues. I can't see any
potential downside for this.


Anecdote; I have implemented List, Set and Map (with mutable builders)
in immutable fashion just for the heck of it.

public interface Set
{
    Set add( T element );
    Set remove( T element );
    :
}
(and also using Visitor pattern instead of Iterables)

It is remarkable how simple these classes becomes by doing so, and
also for multi-threaded client code that for java.util.Collections
need to worry about ConcurrentModificationException one way or the
other, and all my code does so, example for adding; new, copy, add,
assign, which is effectively the immutable pattern anyway.


Cheers
-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to