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
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Part 3: Programming Patterns > Collection Patterns

Chapter 16. Collection Patterns

Organizing collections of objects is a fundamental part of everyday programming. The class frameworks provide several classes for organizing objects into arrays, dictionaries (maps), and sets. Objects in an array have a specific order, addressed by a numeric index. Dictionaries (maps) organize objects into unordered pairs, each pair being a unique key object and a value object. The key object is used to identify and address the value object. Finally, sets are amorphous collections that are neither ordered nor addressable; an object is simply in a set or it's not. The Cocoa framework doesn't provide any tree, linked list, or stack collections.

Collection patterns in Objective-C will present Java programmers with a number of challenges. The biggest will be a false sense of familiarity—faux amis, as the French would say. So much of the collection classes resemble Java that it's easy to forget the subtle differences: the base classes of collections are immutable, keys in a dictionary (map) are always copied, collections can't be modified during enumeration, and so on. Many of these behaviors are only footnotes in the regular documentation. This chapter will highlight these differences so that you'll be acutely aware of them. Some differences are blessings, most require slight changes to your programming habits, and a few can profoundly affect your design.


  

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