|
ValueSingleton
The Value Singleton pattern refers to a Factory that returns exactly one instance per value. The exact semantics of value are left to the implementer, but a value is usually composed by the argument combination passed to the factory function. For example, calling IRI.instance( "http://www.google.com/" ); Will always return the same IRI instance. So you can safely test for IRI equality based on identity iri1 === iri2 ? Instead of having to rely on value inspection iri1.equals( iri2 ). This is arguable faster, cleaner and works fine with native Array functions et Al. The main tradeoff of this approach is that the naming access ( possibly hashing ) cost is payed on creation time. Implementation note: Internally, the IRI class keeps an InvertedWeakKeyDictionary cache, in this case. |
► Sign in to add a comment