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]]