On Wed, Aug 3, 2011 at 11:26 AM, Rickard Öberg <[email protected]> wrote:
>
> None of the methods I mentioned return proxies actually. Do you have any
> examples of what you mean?

Ok, suppose you have a method that return an interface instance.
This interface is defined as follows (this is an assumed dumb example) :

public interface NamedThing {
String getName();
List<NamedThing> getChildren();
int getSize();
}

A NullObject implementation of that class would return the following
getName() => ""
getChildren() => a NullObject instance implementing List (which size()
method will obviously return 0)
getSize() => 0

This way, the object graph returned only contains leaves, and branches
are cut as soon as possible.
In other words, a NullObject proxy can have its algorithm described as follows :
examine return type.
If a boolean instance, return false
If a Number instance, return 0
If a String instance, return 0
If an interface instance, return another NullObject.
In any other case, throw a NotNullObjectCompatible (or you name it) exception.
>
>> When not possible, it would be better to return a Qi4J specific
>> exception, that would be able to carry far more meaning than
>> standard Java one and maybe provide continuation mechanisms (think
>> about an exception that would contain the aforementionned NullObject,
>> or an exception that would provide additionnal debug infos ina
>> structured form, as opposed to the String+StackTrace we usually
>> get).
>
> Sounds incredibly complicated. Got usecase?

Well, not really, and I do understand my explications are rather confuse.
Anyway, I've always found exceptions to be very poor. And I do like
the exceptions to provide me two things :
 1 - An insame amount of details about the failure (in the particular
null case, what precisely is null, and how can I make sure it is not
null in later cases)
 2 - An easy track for fixing error (in that particular case, a
unnulifyWith(Object newValue) method in exception that would put a
default value in object would be incredibly great).

But I do agree with you, all that is incredibly complicated (and
borderline crazy in most cases).

-- 
Nicolas Delsaux

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

Reply via email to