JaroslavTulach at 06:52, 8 October 2018 - 2018-10-08 06:52:00

←Older revision Revision as of 06:52, 8 October 2018
Line 1: Line 1:
-
[[Singletonizer]] is a simplification of [[Factory]] by use of [[Generics]]. It is very useful pattern for creating [[ProviderAPI]]. On the other hand, it is not that useful for [[ClientAPI]], as its use requires an [[OpenClass]] concept.
+
[[Singletonizer]] is a simplification of [[Factory]] by use of [[Generics]]. It is very useful pattern for creating [[ProviderAPI]]. On the other hand, it is not that useful for [[ClientAPI]], as its use requires an [[OpenClass]] concept. [[Singletonizer]] is the simplest way to emulate [[Abstract Data Type]]s in [[OOP]] languages.
 +
 
== Real Example ==
== Real Example ==

JaroslavTulach at 06:49, 25 January 2018 - 2018-01-25 06:49:35

←Older revision Revision as of 06:49, 25 January 2018
Line 1: Line 1:
[[Singletonizer]] is a simplification of [[Factory]] by use of [[Generics]]. It is very useful pattern for creating [[ProviderAPI]]. On the other hand, it is not that useful for [[ClientAPI]], as its use requires an [[OpenClass]] concept.
[[Singletonizer]] is a simplification of [[Factory]] by use of [[Generics]]. It is very useful pattern for creating [[ProviderAPI]]. On the other hand, it is not that useful for [[ClientAPI]], as its use requires an [[OpenClass]] concept.
 +
 +
== Real Example ==
 +
 +
[[Graal]] '''Graph I/O''' [[API]] is using the [[singletonizer]] pattern in its [http://www.graalvm.org/graphio/javadoc/org/graalvm/graphio/package-summary.html javadoc].
 +
 +
== Artificial Sample ==
Instead of having one class representing a [[Factory]] which creates another class representing the ''data'', one can move all the methods into one class:
Instead of having one class representing a [[Factory]] which creates another class representing the ''data'', one can move all the methods into one class:

Apidesign at 20:30, 27 December 2008 - 2008-12-27 20:30:06

←Older revision Revision as of 20:30, 27 December 2008
Line 19: Line 19:
[[Category:APIDesignPatterns]]
[[Category:APIDesignPatterns]]
[[Category:APIDesignPatterns:Creational]]
[[Category:APIDesignPatterns:Creational]]
-
[[Category:APIDesignPatterns:Accuracy]]
+
[[Category:APIDesignPatterns:Clarity]]

JaroslavTulach at 18:52, 25 December 2008 - 2008-12-25 18:52:44

←Older revision Revision as of 18:52, 25 December 2008
Line 13: Line 13:
<source lang="java" snippet="day.end.bridges.DigestImpl"/>
<source lang="java" snippet="day.end.bridges.DigestImpl"/>
-
Btw. the ''DigestImpl'''s '''ACCESSOR''' field in example of [[FriendPackages|friend accessor pattern]] to access protected methods of ''Digestor'' class located in different package.
+
Btw. the ''DigestImpl'''s ''ACCESSOR'' field, which slightly complicates the code, is an example of [[FriendPackages|friend accessor pattern]] allowing us to access '''protected''' methods of ''Digestor'' class located in different package.
<comments/>
<comments/>

JaroslavTulach at 18:33, 25 December 2008 - 2008-12-25 18:33:53

←Older revision Revision as of 18:33, 25 December 2008
Line 9: Line 9:
<source lang="java" snippet="day.end.bridges.CountingDigestor"/>
<source lang="java" snippet="day.end.bridges.CountingDigestor"/>
-
[[Singletonizer]] is useful when representing complex graphs or tree hierarchies. One can have a class in a [[ClientAPI]] that represents each graph's [[wikipedia::Graph_Vertex|vertex]]. There can be tons of its instances. Yet plugging in behaviour for each instance can be quite simple. They can all delegate to single [[Singletonizer]] implementation which handles all their operation. Thus they are basically ''singletonizing'' behaviour of many instances to one - hence the name [[Singletonizer]].
+
[[Singletonizer]] is useful when representing complex graphs or tree hierarchies. One can have a class in a [[ClientAPI]] that represents each graph's [[wikipedia::Graph_Vertex|vertex]]. There can be tons of its instances. Yet plugging in behaviour for each instance can be quite simple. They can all delegate to single [[Singletonizer]] implementation which handles all their operation. Thus they are basically ''singletonizing'' behaviour of many instances to one - hence the name [[Singletonizer]]:
 +
 
 +
<source lang="java" snippet="day.end.bridges.DigestImpl"/>
 +
 
 +
Btw. the ''DigestImpl'''s '''ACCESSOR''' field in example of [[FriendPackages|friend accessor pattern]] to access protected methods of ''Digestor'' class located in different package.
<comments/>
<comments/>

JaroslavTulach at 18:08, 25 December 2008 - 2008-12-25 18:08:26

←Older revision Revision as of 18:08, 25 December 2008
Line 9: Line 9:
<source lang="java" snippet="day.end.bridges.CountingDigestor"/>
<source lang="java" snippet="day.end.bridges.CountingDigestor"/>
-
[[Singletonizer]] is useful when dealing with complex graphs of tree hierarchies. One can have an [[ClientAPI]] with a class that represents a [[wikipedia::Graph_Vertex|vertex]] in a graph. Thus having tons of instances and yet, they all can delegate to just one [[Singletonizer]] implementation that handles all their operation. Thus they are basically ''singletonizing'' number of instances to one - hence the name [[Singletonizer]].
+
[[Singletonizer]] is useful when representing complex graphs or tree hierarchies. One can have a class in a [[ClientAPI]] that represents each graph's [[wikipedia::Graph_Vertex|vertex]]. There can be tons of its instances. Yet plugging in behaviour for each instance can be quite simple. They can all delegate to single [[Singletonizer]] implementation which handles all their operation. Thus they are basically ''singletonizing'' behaviour of many instances to one - hence the name [[Singletonizer]].
<comments/>
<comments/>

JaroslavTulach at 16:30, 25 December 2008 - 2008-12-25 16:30:26

←Older revision Revision as of 16:30, 25 December 2008
Line 14: Line 14:
[[Category:APIDesignPatterns]]
[[Category:APIDesignPatterns]]
-
[[Category:APIDesignPatterns:Evolution]]
+
[[Category:APIDesignPatterns:Creational]]
[[Category:APIDesignPatterns:Accuracy]]
[[Category:APIDesignPatterns:Accuracy]]

JaroslavTulach at 16:12, 25 December 2008 - 2008-12-25 16:12:49

←Older revision Revision as of 16:12, 25 December 2008
Line 10: Line 10:
[[Singletonizer]] is useful when dealing with complex graphs of tree hierarchies. One can have an [[ClientAPI]] with a class that represents a [[wikipedia::Graph_Vertex|vertex]] in a graph. Thus having tons of instances and yet, they all can delegate to just one [[Singletonizer]] implementation that handles all their operation. Thus they are basically ''singletonizing'' number of instances to one - hence the name [[Singletonizer]].
[[Singletonizer]] is useful when dealing with complex graphs of tree hierarchies. One can have an [[ClientAPI]] with a class that represents a [[wikipedia::Graph_Vertex|vertex]] in a graph. Thus having tons of instances and yet, they all can delegate to just one [[Singletonizer]] implementation that handles all their operation. Thus they are basically ''singletonizing'' number of instances to one - hence the name [[Singletonizer]].
 +
 +
<comments/>
[[Category:APIDesignPatterns]]
[[Category:APIDesignPatterns]]
[[Category:APIDesignPatterns:Evolution]]
[[Category:APIDesignPatterns:Evolution]]
[[Category:APIDesignPatterns:Accuracy]]
[[Category:APIDesignPatterns:Accuracy]]

JaroslavTulach: New page: Singletonizer is a simplification of Factory by use of Generics. It is very useful pattern for creating ProviderAPI. On the other hand, it is not that useful for [[ClientAP... - 2008-12-25 16:12:08

New page: Singletonizer is a simplification of Factory by use of Generics. It is very useful pattern for creating ProviderAPI. On the other hand, it is not that useful for [[ClientAP...

New page

[[Singletonizer]] is a simplification of [[Factory]] by use of [[Generics]]. It is very useful pattern for creating [[ProviderAPI]]. On the other hand, it is not that useful for [[ClientAPI]], as its use requires an [[OpenClass]] concept.

Instead of having one class representing a [[Factory]] which creates another class representing the ''data'', one can move all the methods into one class:

<source lang="java" snippet="day.end.bridges.Digestor"/>

This simplifies the life for the implementors of the '''Digestor''' class while retaining the same power as they had before. They have to subclass and implement just one type. Yet they can also have own ''data'' type. Moreover, due to use of [[Generics]] they do not need to deal with any casts or unsafe type checking. Or, just like in following example, one can reuse suitable existing data type:

<source lang="java" snippet="day.end.bridges.CountingDigestor"/>

[[Singletonizer]] is useful when dealing with complex graphs of tree hierarchies. One can have an [[ClientAPI]] with a class that represents a [[wikipedia::Graph_Vertex|vertex]] in a graph. Thus having tons of instances and yet, they all can delegate to just one [[Singletonizer]] implementation that handles all their operation. Thus they are basically ''singletonizing'' number of instances to one - hence the name [[Singletonizer]].

[[Category:APIDesignPatterns]]
[[Category:APIDesignPatterns:Evolution]]
[[Category:APIDesignPatterns:Accuracy]]