4. What is a Singleton?
A singleton is an object that only has one instance for
the lifetime of the application.
Some things are not safe to have more than one
instance running. For example, an updater.
Objective-C classes are singletons by design. You can
take advantage of this when creating singletons.
8. What is a Delegate?
A delegate defines the behavior of a generic class.
This keeps implementation specific behavior out of the
generic class.
Data sources are similar to delegates, except they
define content rather than behavior.
UITableViews use both a delegate and a data source.
11. Gotchas
Use “assign” instead of “retain” to avoid retain cycles.
When using assign, be sure to nullify the delegate
reference when deallocating the object.
Use “weak” instead of “assign” when using ARC.
14. What is Block Delegation?
Similar to a delegate object.
Rather than give an object that has one or more
methods defined, give a block that has the
implementation of one method.
Rule of thumb: If you have three or more delegate
methods, use a delegate. Otherwise, use block
delegation.
Sometimes it’s appropriate to break this rule.
16. Gotchas
Watch out for retain cycles, particularly with “self”
__block __unsafe_unretained id selfRef = self;
__block __weak id selfRef = self;
Don’t forget to copy your blocks. They are created on
the stack.
19. What is MVC?
A strict organization of classes into their different roles.
Model: Any underlying data.
View: The graphical presentation of the data.
Controller: Coordinates the interactions between the
views and model.
Keeps programs modular and makes it easy to swap
out views when needed.
24. What is the Layer Pattern?
Modules of a program can be organized like a stack of
layers.
Strict Layering: A layer can only use the layer directly
below it.
Non-strict Layering: A layer can use any layer below it.
25. Core Data Layers
Application
NSManagedObject Subclass
NSManagedObject
Context
NSManagedObject
NSPersistentStoreCoordinator NSManagedObjectModel
NSPersistentStore
XML SQLite Binary In Memory Custom
26. Gotchas
Occasionally you may find a need to call up a layer. To
do this, you will need to use dependency inversion.
Dependency inversion: A lower layer defines an
interface to interact with other layers. This is often used
with notifications. An upper layer can register itself to
receive these notifications through the defined
interface.
28. What is a Façade?
A façade is a single entry point to a complex collection
of classes.
Makes interaction with complex collections easier and
less dependent on internal implementation.
This is the basis of the layer pattern.
32. What is an Observer?
Sometimes you want to know when an object
changes.
Often used with MVC.
When a model object changes, you want to update
the view(s) accordingly.
The observer pattern is built into every NSObject via
Key-Value Observing (KVO).
36. What is a Proxy?
A proxy receives actions in behalf of another object.
Many types of proxies:
Lazy loading proxy
Distributed (network) proxy (NSDistantObject)
Immutable proxy
NSProxy can be used to make any kind of proxy
object.
40. Gotchas
If you use NSProxy, you need to be very familiar with
message forwarding.
41. Want to Learn More?
Design Patterns: Elements of Reusable Object-
Oriented Software
Every developer should own this book!
Cocoa Design Patterns in the Apple Docs