19. Associative Storage
Associative Storage is one of the oldest and most used patterns in software development. It organizes data and keys so that data can be quickly and easily accessed using the corresponding keys. Associative Storage promotes flexibility and runtime storage efficiency.
Motivation
Use Associative Storage to accomplish the following:
• Efficiently store arbitrary data associated with objects.
• Promote flexibility by delaying the selection of which data to access until runtime.
• Provide object extensibility per instance instead of per class.
• Work around an Objective-C programming language limitation that prevents addition of instance variables without subclassing.
Solution
The NSDictionary
and NSMutableDictionary
classes ...
Get Cocoa Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.