The main motivation before the decorator pattern is to be able to add data and behavior to objects dynamically without relying on inheritance. A decorator usually conforms to the interface of the component its decorating. Lets see this with an example. Am building a system that calculates the price of a pizza. I can have many toppings and the total price of the pizza is calculated based on what toppings I pick. One way to do this would be to use inheritance and class hierarchies like Pizza, CheesePizza, ......
A proxy is an object that can be used to control creation and access of a more complex object thereby deferring the cost of creating it until the time its needed. Below is a simple implementation of the proxy pattern in C#. The ComplexProtectedExpensiveRe... is private to the ProxyContainer and cannot be instantiated by a client. The client creates an instance of the SimpleProxy class which controls its access to the more complex and expensive to create ComplexProtectedExpensiveRe... class. ......