Virtual proxy, remote proxy, and protection proxy are all variants of the Proxy pattern that control access to an object, but each addresses a different concern: lazy creation, remote communication, or authorization.
Key Points: • A virtual proxy defers creation of an expensive object until it's actually needed, saving memory and startup time. • A remote proxy represents an object that lives in a different process or machine, hiding network communication details from the client. • A protection proxy checks permissions before allowing a client to access the real object. • All three implement the same interface as the real subject so the client code doesn't need to change. • They can be combined, for example a remote proxy that also enforces access control.
Example: A virtual proxy might delay loading a large image until it's scrolled into view, a remote proxy might represent a service running on another server via RMI or gRPC, and a protection proxy might block a non-admin user from calling a deleteRecord() method.
Interview Tip: A concise interview answer is:
"Virtual proxy delays object creation for efficiency, remote proxy hides the fact that the real object lives on another machine, and protection proxy enforces access control before delegating to the real object. All three implement the same interface as the real subject so callers don't notice the difference."