<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Djfreema</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Djfreema"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Djfreema"/>
	<updated>2026-06-02T21:25:48Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39594</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39594"/>
		<updated>2010-10-30T18:40:42Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.[[#References|[1]]]  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
The following example of Prototype based programming shows how objects can be reopened and have their methods redefined in ruby&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#The objects are independent, so each of them can redefine methods without worrying about everyone #else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability[[#References|[1]]]&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.[[#References|[1]]]  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Prototype Based Programming. [Online]. http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] C2. (2010, October) Prototype Based Programming. [Online]. http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] taw's blog. (2010, October) Prototype-based Ruby. [Online]. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39593</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39593"/>
		<updated>2010-10-30T18:40:33Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Creation using each method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.[[#References|[1]]]  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
The following example of Prototype based programming shows how objects can be reopened and have their methods redefined in ruby&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#The objects are independent, so each of them can redefine methods without worrying about everyone #else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability[[#References|[1]]]&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.[[#References|[1]]]  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Prototype Based Programming. [Online]. http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] C2. (2010, October) Prototype Based Programming. [Online]. http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] taw's blog. (2010, October) Prototype-based Ruby. [Online]. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39592</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39592"/>
		<updated>2010-10-30T18:39:14Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Example of prototype based programming in ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
The following example of Prototype based programming shows how objects can be reopened and have their methods redefined in ruby&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#The objects are independent, so each of them can redefine methods without worrying about everyone #else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability[[#References|[1]]]&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.[[#References|[1]]]  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Prototype Based Programming. [Online]. http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] C2. (2010, October) Prototype Based Programming. [Online]. http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] taw's blog. (2010, October) Prototype-based Ruby. [Online]. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39591</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39591"/>
		<updated>2010-10-30T18:36:23Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Example of prototype based programming in ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#The objects are independent, so each of them can redefine methods without worrying about everyone #else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability[[#References|[1]]]&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.[[#References|[1]]]  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Prototype Based Programming. [Online]. http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] C2. (2010, October) Prototype Based Programming. [Online]. http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] taw's blog. (2010, October) Prototype-based Ruby. [Online]. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39590</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39590"/>
		<updated>2010-10-30T18:35:57Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Example of prototype based programming in ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#The objects are independent, so each of them can redefine methods without worrying about everyone #else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability[[#References|[1]]]&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.[[#References|[1]]]  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Prototype Based Programming. [Online]. http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] C2. (2010, October) Prototype Based Programming. [Online]. http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] taw's blog. (2010, October) Prototype-based Ruby. [Online]. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39589</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39589"/>
		<updated>2010-10-30T18:35:35Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Criticisms of Prototype based programming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The objects are independent, so each of them can redefine methods without worrying about everyone else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability[[#References|[1]]]&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.[[#References|[1]]]  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Prototype Based Programming. [Online]. http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] C2. (2010, October) Prototype Based Programming. [Online]. http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] taw's blog. (2010, October) Prototype-based Ruby. [Online]. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39588</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39588"/>
		<updated>2010-10-30T18:35:06Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The objects are independent, so each of them can redefine methods without worrying about everyone else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Prototype Based Programming. [Online]. http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] C2. (2010, October) Prototype Based Programming. [Online]. http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] taw's blog. (2010, October) Prototype-based Ruby. [Online]. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39548</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39548"/>
		<updated>2010-10-30T02:18:03Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Negatives of Prototype based programming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The objects are independent, so each of them can redefine methods without worrying about everyone else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Criticisms of Prototype based programming=&lt;br /&gt;
==Classes as types==&lt;br /&gt;
Some argue that, like dynamically typed languages, there are issues with dynamic class definitions.  The usual three items cited are Correctness, Safety, and Predictability&lt;br /&gt;
*Prototype-based languages are said to be less correct because of the dynamic nature of the objects.  It is difficult to check fully if the object or method you have is what you expect.&lt;br /&gt;
*Prototype-based languages are cited as being unsafe because little checking is done at run time on the objects&lt;br /&gt;
*Prototype-based languages are also accused of being highly unpredictable due to the lack of a formal definition of the class structure of an underlying object.&lt;br /&gt;
&lt;br /&gt;
==Compiler speed==&lt;br /&gt;
Compilers written for prototype-based languages are more complex than those written for class based languages.  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39547</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39547"/>
		<updated>2010-10-30T02:10:12Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Example of prototype based programming in ruby=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Hello, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now we just need to copy existing objects:&lt;br /&gt;
&lt;br /&gt;
y = x.clone()&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The objects are independent, so each of them can redefine methods without worrying about everyone else:&lt;br /&gt;
&lt;br /&gt;
z = x.clone()&lt;br /&gt;
&lt;br /&gt;
def x.hello(arg)&lt;br /&gt;
    puts &amp;quot;Guten Tag, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def z.hello(arg)&lt;br /&gt;
    puts &amp;quot;Goodbye, #{arg}!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Guten Tag, world!&amp;quot;&lt;br /&gt;
y.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
z.hello(&amp;quot;world&amp;quot;) # =&amp;gt; &amp;quot;Goodbye, world!&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Negatives of Prototype based programming=&lt;br /&gt;
&lt;br /&gt;
Compilers written for prototype languages are more complex than those written for class based languages.  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39546</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39546"/>
		<updated>2010-10-30T02:08:28Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Inheritance in each method=&lt;br /&gt;
A class based design requires that all relationships are created explicitly in the source.  This means that for a class to be a child of another, that relationship must be explicitly stated in the source at compile time.&lt;br /&gt;
&lt;br /&gt;
An object may have its functionality extended during execution by inclusion of a prototype.  This means that a object can be given any aspect while the code is executing. See [[Unbounded Polymorphism]]&lt;br /&gt;
&lt;br /&gt;
=Negatives of Prototype based programming=&lt;br /&gt;
&lt;br /&gt;
Compilers written for prototype languages are more complex than those written for class based languages.  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39545</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39545"/>
		<updated>2010-10-30T02:07:19Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Creation using each method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
When using classes and set based creation, instances are (usually) bound to their defining classes.  This means that when you create a new object, it must match some defined class.  The resulting object is then said to be an instance of the class, and will always reference functionality contained in and defined by the object's class.&lt;br /&gt;
&lt;br /&gt;
When using prototyping, however, a object may be created either [[http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science|&amp;quot;ex nihilo&amp;quot;]] or by cloning another object.  When creating an object in a language that supports prototyping, methods and variables can be defined at anytime during the life cycle of the object.  The object also contains its own definition of functionality and storage.  This fact allows the functionality of any object to be changed after creation.  This allows the programmer to create a new object by cloning an existing object and, at runtime, change functions and storage.  An example is below:&lt;br /&gt;
&lt;br /&gt;
=Inheritance in each method=&lt;br /&gt;
A class based design requires that all relationships are created explicitly in the source.  This means that for a class to be a child of another, that relationship must be explicitly stated in the source at compile time.&lt;br /&gt;
&lt;br /&gt;
An object may have its functionality extended during execution by inclusion of a prototype.  This means that a object can be given any aspect while the code is executing. See [[Unbounded Polymorphism]]&lt;br /&gt;
&lt;br /&gt;
=Negatives of Prototype based programming=&lt;br /&gt;
&lt;br /&gt;
Compilers written for prototype languages are more complex than those written for class based languages.  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
http://en.wikipedia.org/wiki/Prototype-based_programming&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39544</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=39544"/>
		<updated>2010-10-30T01:55:12Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: Re worded stuff&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
One of the key tenants of object oriented programming is the ability to specify common attributes for like objects.  There are two main ways to do this.  The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different.  The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. Sets=&lt;br /&gt;
When defining like behavior, the first method of doing this is by listing all the like components as you define the class.  This can be done in a few different ways:&lt;br /&gt;
*Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes.  These can be methods, fields, or accessors.  A class that has abstract items is called an abstract class.&lt;br /&gt;
*Interfaces are a type of abstract class that only defines abstract methods.  These classes are used as an answer to multiple inheritance in languages such as Java.  Interfaces allow a behavior contract to be used to specify how objects interact.  A using piece of code can use any implementing object that follows the contract.&lt;br /&gt;
&lt;br /&gt;
However, the second method, prototyping, does not explicitly define any relationships.  Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
A class can be created through its constructor.  This restricts creation to explicit calls to the new method of the class, and prevents changing the objects behavior after the object is instantiated.&lt;br /&gt;
&lt;br /&gt;
A prototype may be created either ''[[ex nihilo]http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science]'' or by cloning another class.&lt;br /&gt;
&lt;br /&gt;
=Inheritance in each method=&lt;br /&gt;
A class based design requires that all relationships are created explicitly in the source.  This means that for a class to be a child of another, that relationship must be explicitly stated in the source at compile time.&lt;br /&gt;
&lt;br /&gt;
An object may have its functionality extended during execution by inclusion of a prototype.  This means that a object can be given any aspect while the code is executing. See [[Unbounded Polymorphism]]&lt;br /&gt;
&lt;br /&gt;
=Negatives of Prototype based programming=&lt;br /&gt;
&lt;br /&gt;
Compilers written for prototype languages are more complex than those written for class based languages.  This raises concerns over efficiency at run time.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
http://en.wikipedia.org/wiki/Prototype-based_programming&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=38947</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=38947"/>
		<updated>2010-10-20T20:23:23Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: Expanded article&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Page Stub for Dzoba and Jeremy for Prototype-based programming&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Prototype based programming is centered around the idea of developing object oriented code by developing functionality at the object level, and then abstracting the code into prototypes.  This allows the programmer the ability to develop objects without the overhead of determining class relations, associations, and requirements.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. classes=&lt;br /&gt;
A class is a definition of an objects behavior and data fields.  This definition generally does not change throughout the execution of the code.&lt;br /&gt;
&lt;br /&gt;
A prototype is an object that is to be used as a basis for developing another object.  Not only does a prototype contain data, but it also contains behaviors for the object.&lt;br /&gt;
&lt;br /&gt;
=Creation using each method=&lt;br /&gt;
A class can be created through its constructor.  This restricts creation to explicit calls to the new method of the class, and prevents changing the objects behavior after the object is instantiated.&lt;br /&gt;
&lt;br /&gt;
A prototype may be created either ''[[ex nihilo]]'' or by cloning another class.&lt;br /&gt;
&lt;br /&gt;
=Inheritance in each method=&lt;br /&gt;
A class based design requires that all relationships are created explicitly in the source.  This means that for a class to be a child of another, that relationship must be explicitly stated in the source at compile time.&lt;br /&gt;
&lt;br /&gt;
An object may have its functionality extended during execution by inclusion of a prototype.  This means that a object can be given any aspect while the code is executing. See [[Unbounded Polymorphism]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
http://en.wikipedia.org/wiki/Prototype-based_programming&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=38863</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=38863"/>
		<updated>2010-10-20T07:29:02Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Page Stub for Dzoba and Jeremy for Prototype-based programming&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Prototype based programming is centered around the idea of developing object oriented code by developing functionality at the object level, and then abstracting the code into prototypes.  This allows the programmer the ability to develop objects without the overhead of determining class relations, associations, and requirements.&lt;br /&gt;
&lt;br /&gt;
=Prototypes vs. classes=&lt;br /&gt;
A class is a definition of an objects behavior and data fields.  This definition generally does not change throughout the execution of the code.&lt;br /&gt;
&lt;br /&gt;
A prototype is an object that is to be used as a basis for developing another object.  New objects are created by first cloning the existing object, and then adding functionality.  This is usually accomplished in languages that allow object's functionality to be changed at run time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
http://www.c2.com/cgi/wiki?PrototypeBasedProgramming&lt;br /&gt;
http://en.wikipedia.org/wiki/Prototype-based_programming&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=38703</id>
		<title>CSC/ECE 517 Fall 2010/ch1 4e dj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_4e_dj&amp;diff=38703"/>
		<updated>2010-10-19T20:19:17Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Page Stub for Dzoba and Jeremy for Prototype-based programming&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37958</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37958"/>
		<updated>2010-10-14T02:30:34Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29| design pattern], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
This diagram illustrates how the Singleton class creates an instance of the Singleton object.  The client classes then create instances of the Singleton class which handles access to the Singleton object.&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37957</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37957"/>
		<updated>2010-10-14T02:30:16Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_pattern_computer_science| design pattern], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
This diagram illustrates how the Singleton class creates an instance of the Singleton object.  The client classes then create instances of the Singleton class which handles access to the Singleton object.&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37956</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37956"/>
		<updated>2010-10-14T02:30:06Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_pattern_computer_science|design pattern], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
This diagram illustrates how the Singleton class creates an instance of the Singleton object.  The client classes then create instances of the Singleton class which handles access to the Singleton object.&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37954</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37954"/>
		<updated>2010-10-14T02:29:37Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]|design pattern], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
This diagram illustrates how the Singleton class creates an instance of the Singleton object.  The client classes then create instances of the Singleton class which handles access to the Singleton object.&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37952</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37952"/>
		<updated>2010-10-14T02:27:37Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29|[design pattern]], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37951</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37951"/>
		<updated>2010-10-14T02:27:15Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29|design&amp;amp;nbsppattern], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37950</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37950"/>
		<updated>2010-10-14T02:26:57Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29|design pattern], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37949</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37949"/>
		<updated>2010-10-14T02:26:41Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29|&amp;quot;design pattern&amp;quot;], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37948</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37948"/>
		<updated>2010-10-14T02:26:17Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
A [[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29|design pattern]], like singleton, is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37947</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37947"/>
		<updated>2010-10-14T02:22:15Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Late Instantiation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading. (See the C++ example)  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37946</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37946"/>
		<updated>2010-10-14T02:20:55Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This diagram is a Universal Modeling Languages (UML) diagram of how a Singleton class would look if implemented in Java.&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope. [[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37944</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37944"/>
		<updated>2010-10-14T02:19:39Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[6]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37943</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37943"/>
		<updated>2010-10-14T02:18:55Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] Dalibor Nasevic (2010, October) Ruby Singleton Pattern Again. [Online]. http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37942</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37942"/>
		<updated>2010-10-14T02:17:39Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger&lt;br /&gt;
  def initialize&lt;br /&gt;
    @log = File.open(&amp;quot;log.txt&amp;quot;, &amp;quot;a&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  @@instance = Logger.new&lt;br /&gt;
&lt;br /&gt;
  def self.instance&lt;br /&gt;
    return @@instance&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def log(msg)&lt;br /&gt;
    @log.puts(msg)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  private_class_method :new&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Logger.instance.log('message 1')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37941</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37941"/>
		<updated>2010-10-14T02:15:55Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Benefits */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37940</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37940"/>
		<updated>2010-10-14T02:15:45Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Drawbacks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  [[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37939</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37939"/>
		<updated>2010-10-14T02:15:18Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[3]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37938</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37938"/>
		<updated>2010-10-14T02:14:06Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Singleton pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37937</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37937"/>
		<updated>2010-10-14T02:13:45Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==test==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37934</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37934"/>
		<updated>2010-10-14T02:09:53Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37933</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37933"/>
		<updated>2010-10-14T02:09:42Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Benefits=&lt;br /&gt;
&lt;br /&gt;
*This pattern allows the programmer to control the instances of a particular object, it ensures that all objects use the same instance of a class.&lt;br /&gt;
&lt;br /&gt;
*The Singleton class has the ability to control the instantiation process since it implements the instantiation functionality.&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37931</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37931"/>
		<updated>2010-10-14T02:08:21Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. [Online]. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern. [Online]. http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37930</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37930"/>
		<updated>2010-10-14T02:07:37Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]] Source Making (2010, October) Singleton Design Pattern. http://sourcemaking.com/design_patterns/singleton&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]] JavaBeginner.com (2010, October) Java Singleton Design Pattern http://www.javabeginner.com/learn-java/java-singleton-design-pattern&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37929</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37929"/>
		<updated>2010-10-14T02:06:26Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] Source Making (2010, October) Singleton Design Pattern. http://sourcemaking.com/design_patterns/singleton&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37928</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37928"/>
		<updated>2010-10-14T02:04:23Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]] C# Corner (2010, October) Creational Patterns - Singleton. [Online]. http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37927</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37927"/>
		<updated>2010-10-14T02:03:12Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37926</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37926"/>
		<updated>2010-10-14T02:01:15Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37925</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37925"/>
		<updated>2010-10-14T02:00:50Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
==Defintions==&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.  A design pattern is a way for a software developer to handle situations using a known solution that has been proven to be effective in the past.  Design patterns also make communicating ideas and concepts between programmers more efficient and understandable.  &lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
[[#References|[1]]]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37921</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37921"/>
		<updated>2010-10-14T01:50:07Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Late Instantiation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
The instance of the class can be created after class loading.  This can be done by only allocating the instance on the first access of the instance variable.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37920</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37920"/>
		<updated>2010-10-14T01:48:38Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Creating the instance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
&lt;br /&gt;
  In the Singleton design pattern we create a single instance of a Singleton class.  Any instantiation of that Singleton class references the same instance of the class.  The pattern also provides a global point of access for the functionality contained in the sole instance of the class.&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
===Early Instantiation===&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
===Late Instantiation===&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37917</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37917"/>
		<updated>2010-10-14T01:41:16Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Drawbacks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
A singleton pattern is a design pattern that restricts the amount of instantiations of a class to one object.  This pattern is implemented when exactly one object is needed to coordinate actions across the entire system.  The restriction of only having one object can sometimes make the system more efficient and allow the programmer to exercise more control over certain actions in the system.  A singleton must satisfy some global access principles, which say all of the classes must be able to access the functionality contained in the singleton class/es.&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
*Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
*This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
*The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
*There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
*The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37916</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37916"/>
		<updated>2010-10-14T01:39:43Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
A singleton pattern is a design pattern that restricts the amount of instantiations of a class to one object.  This pattern is implemented when exactly one object is needed to coordinate actions across the entire system.  The restriction of only having one object can sometimes make the system more efficient and allow the programmer to exercise more control over certain actions in the system.  A singleton must satisfy some global access principles, which say all of the classes must be able to access the functionality contained in the singleton class/es.&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
1) Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
2) This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
3) The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
4) There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
5)  The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.  &lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37915</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37915"/>
		<updated>2010-10-14T01:39:29Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
A singleton pattern is a design pattern that restricts the amount of instantiations of a class to one object.  This pattern is implemented when exactly one object is needed to coordinate actions across the entire system.  The restriction of only having one object can sometimes make the system more efficient and allow the programmer to exercise more control over certain actions in the system.  A singleton must satisfy some global access principles, which say all of the classes must be able to access the functionality contained in the singleton class/es.&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
class genericFactory&lt;br /&gt;
  include Singleton&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
1) Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
2) This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
3) The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
4) There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
5)  The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.  &lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37914</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37914"/>
		<updated>2010-10-14T01:38:14Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
A singleton pattern is a design pattern that restricts the amount of instantiations of a class to one object.  This pattern is implemented when exactly one object is needed to coordinate actions across the entire system.  The restriction of only having one object can sometimes make the system more efficient and allow the programmer to exercise more control over certain actions in the system.  A singleton must satisfy some global access principles, which say all of the classes must be able to access the functionality contained in the singleton class/es.&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  include Singleton&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
1) Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
2) This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
3) The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
4) There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
5)  The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.  &lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37913</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3f lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3f_lj&amp;diff=37913"/>
		<updated>2010-10-14T01:37:58Z</updated>

		<summary type="html">&lt;p&gt;Djfreema: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Singleton Pattern in Static and Dynamic languages'''&lt;br /&gt;
&lt;br /&gt;
=Singleton pattern=&lt;br /&gt;
A singleton pattern is a design pattern that restricts the amount of instantiations of a class to one object.  This pattern is implemented when exactly one object is needed to coordinate actions across the entire system.  The restriction of only having one object can sometimes make the system more efficient and allow the programmer to exercise more control over certain actions in the system.  A singleton must satisfy some global access principles, which say all of the classes must be able to access the functionality contained in the singleton class/es.&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[Image:IC73826.gif|500px|center]]&lt;br /&gt;
===Sequence Diagram===&lt;br /&gt;
[[Image:CR2.gif|500px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
When this pattern is implemented then it must only have one instantiation of a class and that class must satisfy the global access principles.  The pattern requires a mechanism to access the singleton class without instantiating another class object and a mechanism to persist the value of class members among class objects.  [[#References|[1]]]&lt;br /&gt;
&lt;br /&gt;
==Creating the instance==&lt;br /&gt;
The instance can be created with a static constructor in static languages.  (See the java example below)  This means that the single instance is created on program start up and all new methods are private and never used except by the singleton class itself.&lt;br /&gt;
&lt;br /&gt;
In static languages, this is accomplished by setting the constructors to private and controlling creation of instance of the object from within the object itself.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, this is done by changing the access level of the constructor to prevent use outside the class just as in the static patterns.&lt;br /&gt;
&lt;br /&gt;
==Accessing the instance==&lt;br /&gt;
&lt;br /&gt;
In static languages, such as Java, the Singleton class will have a method which returns the instance of the Singleton class so that the other classes can use the functionality encapsulated in the Singleton class.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages, such as Ruby, if a class needs to access the functionality within the Singleton class then it simply needs to access the instance variable @instance and all the functionality therein.&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java's API includes a Singleton class which implements the static version of the Singleton pattern.  Java's implementation of the Singleton pattern only allows the programmer to create one instance of the Singleton class.  The Singleton class automatically creates INSTANCE when it is initialized.  The getInstance() method returns the single instance of the class that has been initialized.  Java also utilizes a constructor to initialize the Singleton class.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    private static final Singleton INSTANCE = new Singleton();&lt;br /&gt;
   &lt;br /&gt;
    // Private constructor prevents instantiation from other classes&lt;br /&gt;
    private Singleton() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static Singleton getInstance() {&lt;br /&gt;
        return INSTANCE;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby implements the Singleton pattern by privatizing the &amp;quot;new&amp;quot; method and creates an instance variable called @instance.  This implementation guarantees that the class will not be able create more than one instantiation of itself and that the system will have the global access privileges since the @instance variable has a global scope.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  include Singleton&lt;br /&gt;
&lt;br /&gt;
==C++==&lt;br /&gt;
&lt;br /&gt;
// Declaration&lt;br /&gt;
class Singleton {&lt;br /&gt;
public: &lt;br /&gt;
    static Singleton* Instance();&lt;br /&gt;
protected: &lt;br /&gt;
    Singleton();&lt;br /&gt;
private:&lt;br /&gt;
    static Singleton* _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Implementation &lt;br /&gt;
Singleton* Singleton::_instance = 0;&lt;br /&gt;
&lt;br /&gt;
Singleton* Singleton::Instance() {&lt;br /&gt;
    if (_instance == 0) {&lt;br /&gt;
        _instance = new Singleton;&lt;br /&gt;
    }&lt;br /&gt;
    return _instance;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=Drawbacks=&lt;br /&gt;
&lt;br /&gt;
1) Unit tests are much harder to write when using the Singleton pattern&lt;br /&gt;
&lt;br /&gt;
2) This pattern reduces the potential for parallelism within a program since the threads must be serialized.&lt;br /&gt;
&lt;br /&gt;
3) The overhead of checking whether there is an instance of a class that already exists every time an objects requests a reference.  Although the overhead is minuscule, this could be a serious problem for systems which don't have the resources to waste.  &lt;br /&gt;
&lt;br /&gt;
4) There may be some development confusion with implementing the singleton class (especially one defined in a class library) because developers may forget that they cannot use the &amp;quot;new&amp;quot; keyword to instantiate the object.&lt;br /&gt;
&lt;br /&gt;
5)  The singleton design pattern doesn't address the issue of deleting the single object.  Some languages implement memory management which means that the Singleton class can only be unallocated by itself since it holds a private reference to the instance of itself.  In languages that don't provide memory management, then the single instance can be deleted but it will cause a dangling reference to that object.  &lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
[[#References|[1]]] Wikipedia. (2010, October) Wikipedia - Singleton_Pattern. [Online]. http://en.wikipedia.org/wiki/Singleton_pattern#Traditional_simple_way&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]] Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. (October 2004) Head First design patterns. [Print.]&lt;/div&gt;</summary>
		<author><name>Djfreema</name></author>
	</entry>
</feed>