Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Chapter 28. Managers Managers are classes that manage instances of other classes. Examples of Cocoa manager classes include NS- FileManager , NSFontManager , NSInputManager , and NSLayoutManager . Managers simplify the creation and management of reusable resources such as fonts and encapsulate implementation details. For example, the NS- FileManager class provides methods for managing files from file systems as diverse as DOS FAT, Apple HFS +, Network File System, UFS, and ISO 9660 without requiring any system-specific code in applications. Some managers also act as controllers within the Model View Controller pattern. Motivation Offer a uniform interface for managing the instantiation of and access to a group of related objects. Many managers use and extend the Singleton pattern; they are singletons themselves, and they may ensure that the objects they manage are unique. Solution It is common in application design to have a collection of objects that need to be unique but at the same time are not singletons. For example, consider fonts. Because an application may use many different fonts, the object used to encapsulate a font will probably be instantiated multiple times and therefore is not a singleton. At the same time, there is no need for multiple instances all encapsulating the same exact font. It makes sense to control the creation of font instances so that whenever a specific typeface is requested, the same instance is returned.