On Sat, 2002-02-16 at 14:05, Christian Asmussen wrote:
> I got across a problem, and would like to know if you guys have a formal
> way of dealing with it. Supose we have the following recursive method
>
> public int getDepth(){
> return getParent() == null ? 0 : getParent().getDepth() + 1;
> }
>
>
> If an interface disigner creates an object with "setParent(this)" then
> getDepth would cause an infinite loop. Depending on the method, this
> could cause a whole server to go OOME. Whats the best for to deal whit
> this? I thought of three ways of avoiding it. What's the best one?
If in this particular case you required an acyclic graph of objects then
you could either use something like a class invariant or an assertion to
make sure that the parameter to setParent(Object o) isn't itself.
--
jvz.
Jason van Zyl
[EMAIL PROTECTED]
http://tambora.zenplex.org
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>