Factory Methods

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.

posted @ 2017-06-28 10:57  2021年的顺遂平安君  阅读(44)  评论(0编辑  收藏  举报