Hi,

On Wed, Jan 13, 2010 at 4:16 PM, Carsten Ziegeler <[email protected]> wrote:
> ...I've been thinking lately about identity of our objects, especially
> resource objects and adaptables....

Identity crisis? Ok, I'll bite ;-)

> Resource a = resolver.getResource("/a/b");
> Resource b = resolver.getResource("/a/b");
>

> What should be true? a == b a.equals(b) ?

Equals: yes
== : I don't care, leave it undefined

> Next question: We get the same adaptable from a resource:
>
> Node n1 = a.adaptTo(Node.class);
> Node n2 = a.adaptTo(Node.class);
>
> Again: n1 == n2? n1.equals(n2)?

== : I don't care, leave it undefined

Depends on what we're adapting to.

In case of a Node I'd expect equals to be true, but ideally that
should only happen if the node hasn't changed in between adaptTo
calls.

> ...Think about a resource resolver being used for a single request
> and getting the same resource during the request several times. Should
> it be possible to return different resources because the repository has
> changed during the request?...

I think so, the application should accept receiving different values
for the same resources during the processing of a request. Nodoby says
Sling is supposed to be transactional during processing of a request.

If one needs a resource to stay stable during a whole request, they
should cache it themselves in the request attributes for example.

So in short: equals should do the right thing, I don't care about ==,
and resources can change at any time. And when adapting resources to
Foo, it's Foo semantics that prevail.

And I'm sure people will find edge cases where the above is problematic ;-)

-Bertrand

Reply via email to