Free Trial

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

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 5. Dynamic Creation > Examples in Cocoa

Examples in Cocoa

Cocoa uses this pattern frequently, often in places where it might be convenient to allow a custom class to be inserted. Chapter 13, which discusses the Singleton pattern, shows how dynamic creation can be applied in this way. The NSApplication class is an example of a singleton in Cocoa, which uses dynamic creation as part of its implementation.

Cocoa uses dynamic creation to implement much of its Applescript support. The reference documentation lists several classes such as NSCloneCommand, NSCountCommand, NSCreateCommand, and so on—class names all ending in “Command.” These are used by Cocoa’s Applscript support in a way similar to the RPN example in this chapter. In this case, Applescript commands are mapped to a Cocoa objects that implement them. Dynamic creation is used to locate and instantiate an object of the correct class for each command.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint