Graphics Programs Reference
In-Depth Information
Here are some best practices: If parts of an application's request logic can work independ-
ently of the rest, then the logic should be split across multiple stores. On the other hand, if
an application's request logic contains chunks of similar code - even if it's interacting
with several external sources, then it is best to keep the logic in one tidy class. Doing so
makes your code easier to read, maintain, debug, and reuse when possible.
Once you have determined how many stores an application should have and what external
sources they will be dealing with, then you can start designing individual stores according
to what they need to accomplish. For example, in Nerdfeed , the store needs to fetch two
RSS feeds. So it must know how to work with a web server in general and the BNR and
iTunes web servers in particular. Another example is the BNRImageStore in Homep-
wner . That store object needed to know how access and store images in a cache on the
filesystem.
Determining singleton status
The next item on the agenda is whether a store should be a singleton or instantiable. The
stores you've created have all been singletons, but you used a store object that was not: a
CLLocationManager . What's the difference? In Whereami , an instance of CLLoca-
tionManager s had options. It could tune how accurate it was or how often it updated a
controller. If a store needs to offer these kinds of options, then it's best to allow multiple
instances of it to be created.
Another thing you should consider is whether a store needs to maintain a cache of data. If
it does, then it should be a singleton so that every controller can have access to the same
cache. This is the reason the stores you've created have been singletons.
BNRItemStore , BNRImageStore , and BNRFeedStore all maintained caches of
data.
You can think of login credentials for a web service as similar to a cache. Both are “data
that a store is required to maintain.” It doesn't make sense to make multiple instances of a
store that maintains login credentials because you would be maintaining multiple copies
of the same data.
Search WWH ::




Custom Search