此内容没有您所选择的语言版本。
16.24. Name Factories
The use of a factory may seem like a disadvantage and unnecessary complexity, but there actually are several benefits. First, it hides the concrete implementations, which is very appealing if an optimized implementation can be chosen for particular situations. It also simplifies the usage, since Name only has a few methods. Third, it allows the factory to cache or pool instances where appropriate to help conserve memory. Finally, the very same factory actually serves as a conversion mechanism from other forms. We'll actually see more of this later in this chapter, when we talk about other kinds of graph properties.
The factory for creating Name objects is called NameFactory and is available within the
ExecutionContext, via the getValueFactories() method.
We'll see how names are used later on, but one more point to make: Name is both serializable and comparable, and all implementations should support
equals(...) and hashCode() so that Name can be used as a key in a hash-based map. Name also extends the Readable interface, which we'll learn more about later in this chapter.