At first glance, you may wonder what's the difference of a Proxy and a Decorator? Why should we propose such a pattern? A Decorator is aimed at docorating the original object, that is to provide more functions before or after the operation sent to the object. However, Proxy does not take the trouble to do more than sending the request.
Useless guys, you might wonder. However, you are wrong. The basic usage of a Proxy is to put off the real expense when it is inevitable. That's to say, RealSubject is something once created costing much time. Then its basic information can be obtained and stored in a Proxy object which acts in the same way as RealSubject does. So if only lightweight operations inquring about the basic information, there is no need to instantiate one immediately.
The indirection of Proxy can also be useful in the case of copy-on-write: The Proxy keeps the copied object and the copy needn't be carried out if the original one isn't modified. What's more the Proxy can protect the object in some way.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment