The class Library is the central source of information in a simple library system. If holds lot of methods like
Catalog<Borrower> getBorrowerCatalog() {...} Catalog<Book> getBookCatalog() {...}However these methods are of no particular interest in this exercise - so you might just as well avoid them.
How do we ensure that
The answer is: Use the singleton pattern.
Example: SingletonComparer
Program the class Library (eager initialization of the singleton)
private
private static readonly Library Instance = new Library();
// eagerpublic readonly Library Instance
property. // the property should be read-only (get, but no set)In the above question you used eager initialization: The single instance is created as soon as the class is loaded into the virtual maching
Make another class LibraryLazy where you use the lazy version of the singleton design pattern: The single instance is created when the first client uses the Instance property
Library lib = Library.Instance
Do you need to override the equals method (from Object) in a singleton class?
The answer is "no"! Next question is why?