NSInteger value = 5;
result = (value != 0) ? x : y;
int a = 1, b = 2, c = 3, d = 4;
int x = 10, y = 5;
int result = a > b ? x = c > d ? c : d : y;
- are reusable solutions to common problems
in software design.
- They’re templates designed to help you write
code that’s easy to understand and reuse.
- They also help you create loosely coupled
code so that you can change or replace
components in your code without too much
of a hassle.
• make a software library easier to
use, understand and test, since the
facade has convenient methods for
• make the library more readable, for
the same reason;
• reduce dependencies of outside
code on the inner workings of a
library, since most code uses the
facade, thus allowing more
ﬂexibility in developing the system;
• wrap a poorly designed collection
of APIs with a single well-designed
API (as per task needs).
Decorator (Wrapper, Adapter)
is a design pattern that allows behavior to be
added to an individual object, either statically
or dynamically, without affecting the behavior
of other objects from the same class.
This is an important pattern. Apple uses this approach in most of the UIKit
is a behavioral design pattern in which an object is used to represent
and encapsulate all the information needed to call a method at a
NSMethodSignature * mySignature = [NSMutableArray
NSInvocation * myInvocation = [NSInvocation
NSString * myString = @"String";
//Next, you would specify which object to send the message to:
//Specify the message you wish to send to that object:
//And fill in any arguments for that method:
[myInvocation setArgument:&myString atIndex:2];
//Note that object arguments must be passed by pointer.
//At this point, myInvocation is a complete object, describing a message that can be sent. To
actually send the message, you would call:
An NSInvocation is an Objective-C message rendered
static, that is, it is an action turned into an object.