0
Iwan de Beer
<ul><li>Ensure that a Class has only one  Instance </li></ul><ul><li>Provide a  Global Reference  to the Instance  </li></ul>
<ul><li>Where can you use it? </li></ul><ul><li>Attributes </li></ul><ul><li>Requirements </li></ul><ul><li>Advantages and...
<ul><ul><li>State  Objects </li></ul></ul><ul><ul><ul><li>ie. Global Application Settings </li></ul></ul></ul><ul><ul><li>...
<ul><li>Single Instance  at Runtime </li></ul><ul><li>Responsible for  own Creation </li></ul><ul><li>Lazy Instantiation <...
<ul><li>Private, Parameterless  Constructor </li></ul><ul><li>Public   Static   Read-Only  Instance Property </li></ul><ul...
<ul><li>Simpler  Consumer Code </li></ul><ul><li>Less  Overhead </li></ul><ul><li>Cleaner  than a Collection of Global Var...
<ul><li>Global State </li></ul><ul><li>Over Use   Anti-Pattern </li></ul>
<ul><li>Compiler  responsible for Instantiation  of Static Class </li></ul><ul><ul><li>Developer cannot control  when  the...
<ul><li>Thread-Safety </li></ul><ul><ul><li>Creation </li></ul></ul><ul><ul><li>Methods </li></ul></ul><ul><li>[ThreadStat...
<ul><li>http://en.wikipedia.org/wiki/Singleton_pattern </li></ul><ul><li>http://www.yoda.arachsys.com/csharp/singleton.htm...
Upcoming SlideShare
Loading in...5
×

Singletons

504

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
504
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Singletons"

  1. 1. Iwan de Beer
  2. 2. <ul><li>Ensure that a Class has only one Instance </li></ul><ul><li>Provide a Global Reference to the Instance </li></ul>
  3. 3. <ul><li>Where can you use it? </li></ul><ul><li>Attributes </li></ul><ul><li>Requirements </li></ul><ul><li>Advantages and Disadvantages </li></ul><ul><li>Singleton versus Static Class </li></ul><ul><li>Multi-Threading </li></ul>
  4. 4. <ul><ul><li>State Objects </li></ul></ul><ul><ul><ul><li>ie. Global Application Settings </li></ul></ul></ul><ul><ul><li>Data Access Objects </li></ul></ul><ul><ul><ul><li>ie. Sharing DataContexts </li></ul></ul></ul><ul><ul><li>Utility Classes </li></ul></ul><ul><ul><ul><li>ie. Global Utility Classes </li></ul></ul></ul>
  5. 5. <ul><li>Single Instance at Runtime </li></ul><ul><li>Responsible for own Creation </li></ul><ul><li>Lazy Instantiation </li></ul>
  6. 6. <ul><li>Private, Parameterless Constructor </li></ul><ul><li>Public Static Read-Only Instance Property </li></ul><ul><li>Sealed </li></ul>
  7. 7. <ul><li>Simpler Consumer Code </li></ul><ul><li>Less Overhead </li></ul><ul><li>Cleaner than a Collection of Global Variables </li></ul>
  8. 8. <ul><li>Global State </li></ul><ul><li>Over Use Anti-Pattern </li></ul>
  9. 9. <ul><li>Compiler responsible for Instantiation of Static Class </li></ul><ul><ul><li>Developer cannot control when the Static Class is Instantiated </li></ul></ul><ul><li>Singleton Class responsible for Instantiation </li></ul><ul><ul><li>Some degree of control over when the Singleton Class is Instantiated </li></ul></ul><ul><li>Instance Property </li></ul><ul><ul><li>Static Class is accessed by the Class Name – No access to the Instance </li></ul></ul><ul><ul><li>Singleton is accessed by Instance Property </li></ul></ul>
  10. 10. <ul><li>Thread-Safety </li></ul><ul><ul><li>Creation </li></ul></ul><ul><ul><li>Methods </li></ul></ul><ul><li>[ThreadStatic] Attribute </li></ul><ul><ul><li>Single Instance per Thread </li></ul></ul><ul><ul><li>Workaround when Methods aren’t Thread-safe </li></ul></ul>
  11. 11. <ul><li>http://en.wikipedia.org/wiki/Singleton_pattern </li></ul><ul><li>http://www.yoda.arachsys.com/csharp/singleton.html </li></ul><ul><li>http://msdn.microsoft.com/en-us/library/ms954629.aspx </li></ul><ul><li>http://msdn.microsoft.com/en-us/library/ms998558.aspx </li></ul><ul><li>http://msdn.microsoft.com/en-us/library/ms998558.aspx </li></ul><ul><li>http://aspalliance.com/827_Gang_of_Four_GOF_Design_Patterns.all </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×