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

Earlier in this lecture we had a problem with one Random object per Die object

 

/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/random-supplier/RandomSingleton.csA singleton Random class.


/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/random-supplier/die.csA Die class that uses singleton Random.


/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/random-supplier/dieApp.csA Die application class.


/user/normark/oop-csharp-1/sources/c-sharp/patterns/singleton/random-supplier/outputOutput from the Die application class.


By using a Singleton Random we ensure that there exists only one Random object