Content deleted Content added
m →Drawbacks: HTTP to HTTPS for Blogspot |
|||
(10 intermediate revisions by 7 users not shown) | |||
Line 1:
{{Short description|Software engineering design pattern}}
{{Plain image with caption|Image:Multiton.svg|UML diagram of the multiton}}
In [[software engineering]], the '''multiton pattern''' is a [[design pattern (computer science)|design pattern]] which generalizes the [[singleton pattern]]. Whereas the [[singleton pattern | singleton]] allows only one instance of a class to be created, the multiton pattern allows for the controlled creation of multiple instances, which it manages through the use of a [[associative array|map]].
Rather than having a single instance ''per application'' (e.g. the {{Javadoc:SE|package=java.lang|java/lang|Runtime}} object in the [[
The multiton pattern does not explicitly appear as a pattern in the highly regarded [[object-oriented programming]] textbook ''[[Design Patterns]]''.<ref>{{cite book |last1=O'Docherty |first1=Mike |title=Object-oriented analysis and design: understanding system development with UML 2.0 |date=2005 |publisher=Wiley |___location=Chichester |isbn=0470092408 |page=341}}</ref> However, the book describes using a '''registry of singletons''' to allow subclassing of singletons,<ref>{{cite book |title=Design patterns: elements of reusable object-oriented software |date=2011 |publisher=Addison-Wesley |___location=Boston, Mass. Munich |isbn=0-201-63361-2 |page=130}}</ref> which is essentially the multiton pattern.{{Citation needed|date=April 2012}}
==Description==
While it may appear that the multiton is a [[hash table]] with synchronized access there are two important distinctions. First, the multiton does not allow clients to add mappings. Secondly, the multiton never returns a [[
Since the object pool is created only once, being a member associated with the class (instead of the instance), the multiton retains its flat behavior rather than evolving into a [[Tree (data structure)|tree structure]].
Line 14 ⟶ 15:
==Drawbacks==
This pattern, like the [[Singleton pattern]], makes [[unit testing]] far more difficult,<ref>{{Cite web | url=
With garbage collected languages it may become a source of memory leaks as it introduces global strong references to the objects.
Line 62 ⟶ 63:
public override string ToString()
{
return $"My type is
}
// Sample usage
public static void Main(string[] args)
{
Console.WriteLine(m0);
Line 86 ⟶ 87:
* [https://github.com/PureMVC/puremvc-as3-multicore-framework/blob/master/src/org/puremvc/as3/multicore/patterns/facade/Facade.as Multiton usage in PureMVC Framework for ActionScript 3]
* [http://gen5.info/q/2008/07/25/the-multiton-design-pattern/ Article with a C# Multiton implementation, example of use, and discussion of memory issues]
{{Design Patterns patterns}}
[[Category:Software design patterns]]
|