Search code examples
javaxmldesign-patternsdom4jflyweight-pattern

How does dom4j library implements Flyweight pattern?


I can see in dom4j library a number of classes with Flyweight prefix: FlyweightAttribute, FlyweightComment, FlyweightText etc. Here is what java doc is saying in the case of FlyweightText:

FlyweightText is a Flyweight pattern implementation of a singly linked, read-only XML Text. This node could be shared across documents and elements though it does not support the parent relationship.

However, I can't seem to find in the code instance pool nor where these instances are shared between documents.

Is this feature implemented at all in the library? If yes, where is the code that implements it?


Solution

  • I've just looked through the sources of 1.6.1. Looks like these Flyweight classes are just peaces of original ideas. At least they are not flyweights in the GoF sense (I don't see any method requires extrinsic state as an argument).

    Why don't you ask James Strachan ([email protected]) who is the author of these classes?