[jdom-interest] How about a general purpose Object reference?

bob bob at accurev.com
Mon Oct 9 07:02:30 PDT 2000


While I personally haven't tripped over needing this with JDOM, other
similar APIs I've worked with (Versant ODMB, for example) have allowed
an Object/void* to be affixed to their structures.  Typically, I've
seen it called 'UserData'.

  Object getUserData();
  void setUserData(Object anything);

Though, that's an extra several bytes on possibly hundreds/thousands
of objects, many times, possibly unused.  (Versant only allowed
attaching UserData to a Session object, and a few other classes
which weren't instantiated all-that-many times.)

Anyhow:  Yes, it's a pattern that's been used before, but I'm
not certain if the trade-off is worth it.

You could always maintain an external Map to maintain association
of UserData to JDOM stuff.

  Object myUserData = UserDataManager.getInstance().getUserData(myElement);

Ugly, sure, but it won't incur extra bytes of holding a null reference
for possibly hundreds of Elements without any UserData.

	-bob


> My question is: I'd like to add temporary 
> information to objects in a JDOM document
> tree (for exsample locking information), so I tought
> it woud be neat if the Document, Element and so
> fort classes had a general purpose Object
> reference for use by application programmers
> wich woud be ignored by JDOM itself.
> 
> public Object getGpObjectRef()
> public void setGpObjectRef(Object object)
> 
> Is there any compelling reasons not to do this? 
> 
> I can see it will dirty up the api somewhat but
> it woud be wery flexible.




More information about the jdom-interest mailing list