Lecture overview -- Keyboard shortcut: 'u'  Previous page: Object-oriented Design Patterns -- Keyboard shortcut: 'p'  Next page: A Singleton Random Class -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 25 : 29
Object-oriented Programming in C#
Reference types, Value types, and Patterns
The Singleton pattern

Problem: For some classes we wish to guarantee that at most one instance of the class can be made.

Solution: The singleton design pattern

/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/template/singleton.csA template of a singleton class.


/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/die/singleton-die.csA singleton Die class.


/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/die/dieApp.csApplication of the singleton Die class.


/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/die/outputOutput of singleton Die application.


A singleton Die is - most probably - not very useful.

On the next slide we will show a singleton Random, which solves a real problem