But you might want to rename your factories to, say, builders. Take a look at javax.xml.parsers.DocumentBuilderFactory, which procudes DocumentBuilder instances, which in turn produce Documents
Looking into the DocumentBuilderFactory example, another option arises:
have an abstract FooFactory
make a static newInstance() method there (with parameters)
let newInstance() return the appropriate implementation of FooFactory
Although the answer by Bozho is pretty good, I'd really consider FooFactoryFactory even if it may sound silly. It conveys the intent like nothing else.
Alternative names are FooMetaFactory and FooPreFactory.
A possible different naming convention is FooParent and FooGrandParent.
发布评论
评论(3)
FooFactoryCreator
FooFactoryProvider
但是您可能想将工厂重命名为“builders”。看一下
javax.xml.parsers.DocumentBuilderFactory
,它生成DocumentBuilder
实例,这些实例又生成Document
。 DocumentBuilderFactory 示例,出现另一个选择:
FooFactory
static newInstance()
方法(带参数)newInstance() 返回
FooFactory
的适当实现FooFactoryCreator
FooFactoryProvider
But you might want to rename your factories to, say, builders. Take a look at
javax.xml.parsers.DocumentBuilderFactory
, which procudesDocumentBuilder
instances, which in turn produceDocument
sLooking into the
DocumentBuilderFactory
example, another option arises:FooFactory
static newInstance()
method there (with parameters)newInstance()
return the appropriate implementation ofFooFactory
在创建和销毁 Java 对象:第 1 部分中,作者建议,“静态工厂方法的一个优点是,与构造函数不同,它们有名称。” –约书亚·布洛赫。您可能会从文章中得到一些想法。
In Creating and Destroying Java Objects: Part 1, the author suggests, "One advantage of static factory methods is that, unlike constructors, they have names." –Joshua Bloch. You may get some ideas from the article.
尽管 Bozho 的答案非常好,但我真的会考虑 FooFactoryFactory,即使它听起来很愚蠢。它传达的意图是独一无二的。
替代名称为
FooMetaFactory
和FooPreFactory
。可能的不同命名约定是
FooParent
和FooGrandParent
。Although the answer by Bozho is pretty good, I'd really consider
FooFactoryFactory
even if it may sound silly. It conveys the intent like nothing else.Alternative names are
FooMetaFactory
andFooPreFactory
.A possible different naming convention is
FooParent
andFooGrandParent
.