Decorator Pattern focuses on dynamically adding functions to an object, while Proxy Pattern focuses on controlling access to an object.
Relationship between a Proxy and the real subject is typically set at compile time, Proxy instantiates it in some way, whereas Decorator is assigned to the subject at runtime, knowing only subject’s interface.
//client for Decorator publicclassClient{ publicstaticvoidmain(String[] args){ //the client designate which class the decorator decorates Componentcomponent=newDecorator(newConcreteComponent()); … } }