The static factory method pattern is a way to encapsulate object creation. Without a factory method, you would simply call the class's constructor directly: Foo x = new Foo()
. With this pattern, you would instead call the factory method: Foo x = Foo.create()
. The constructors are marked private, so they cannot be called except from inside the class, and the factory method is marked as static so that it can be called without first having an object.
Factory Methods
最新推荐文章于 2024-02-23 11:18:34 发布