The proxy pattern
The proxy design pattern gets its name from the proxy (also known as surrogate) object used to perform an important action before accessing the actual object. There are four well-known types of proxy. They are as follows:
- A virtual proxy, which uses lazy initialization to defer the creation of a computationally expensive object until the moment it is actually needed.
- A protection/protective proxy, which controls access to a sensitive object.
- A remote proxy, which acts as the local representation of an object that really exists in a different address space (for example, a network server).
- A smart (reference) proxy, which performs extra actions when an object is accessed. Examples of such actions are reference counting and thread-safety checks.
Real-world examples
Chip cards offer a good example of how a protective proxy is used in real life. The debit/credit card contains a chip that first needs to be read by the ATM or card reader. After...