JaroslavTulach: APIDesignPatterns:Factory moved to Factory - 2008-11-15 12:36:28

APIDesignPatterns:Factory moved to Factory

←Older revision Revision as of 12:36, 15 November 2008

JaroslavTulach at 12:26, 15 November 2008 - 2008-11-15 12:26:24

←Older revision Revision as of 12:26, 15 November 2008
Line 10: Line 10:
All these details can be implemented and are hidden to some extent from the user of the [[API]]. It is impossible to achieve this with plain constructor.
All these details can be implemented and are hidden to some extent from the user of the [[API]]. It is impossible to achieve this with plain constructor.
-
[[Category:APIDesignPatters]]
+
[[Category:APIDesignPatterns]]
-
[[Category:APIDesignPatters:Creational]]
+
[[Category:APIDesignPatterns:Creational]]
-
[[Category:APIDesignPatters:Encapsulation]]
+
[[Category:APIDesignPatterns:Encapsulation]]

JaroslavTulach: New page: Factory method is well know design pattern useful in API design too. In general, instead of making constructor of some class public, you can reveal a public static method that returns ... - 2008-11-15 12:25:42

New page: Factory method is well know design pattern useful in API design too. In general, instead of making constructor of some class public, you can reveal a public static method that returns ...

New page

Factory method is well know design pattern useful in [[API]] design too. In general, instead of making constructor of some class public, you can reveal a public static method that returns instance of the class:

<source lang="java" snippet="aserverinfo.regularcreate"/>

This has few benefits from the point of [[API]] [[evolution]]:
* the class is not subclassable, which solves a lot of nasty evolution problems by itself
* one can create a cache or have pool of instances to return
* the whole factory method can be synchronized, preventing parallel access
* one can return subclass of the return type, not the type itself
All these details can be implemented and are hidden to some extent from the user of the [[API]]. It is impossible to achieve this with plain constructor.

[[Category:APIDesignPatters]]
[[Category:APIDesignPatters:Creational]]
[[Category:APIDesignPatters:Encapsulation]]