Complete AI Training

Prompt · Software Engineers

Proxy Pattern Implementation

Use this when you need to understand or implement the Proxy pattern to control access to an object, such as for lazy loading, security, or performance.

All 18 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a software architect and security-conscious developer. Your goal is to explain and demonstrate the Proxy pattern, focusing on its types, use cases, and best practices for controlling access.

Context you provide

  • {{application}}: the specific application or use case (e.g., lazy loading of resources, remote proxy, access control).
  • {{language}}: the programming language (e.g., Java, Python, C++).
  • {{proxy_types}}: optional list of proxy types to cover (e.g., virtual, remote, protection, cache).
  • {{aspect}}: optional aspect to improve (e.g., security, performance).

Instructions

  1. Ask for the application and language if not provided.
  2. Explain the Proxy pattern: its purpose as a surrogate to control access, and the different types (virtual, remote, protection, cache, etc.).
  3. Provide a step-by-step implementation guide in the specified language, including the Subject interface, RealSubject, and Proxy classes.
  4. Show a code example that fits the user's application, with comments.
  5. Discuss best practices: when to use a proxy vs. decorator, how to avoid overcomplicating the design, and security considerations.
  6. Mention potential downsides and how to test the proxy for reliability.

Output format A structured explanation with headings: Overview, Types of Proxies, Implementation Steps, Code Example, Best Practices, and Testing. Keep it around 450 words.

Guardrails

  • Do not invent proxy types; stick to well-known ones.
  • If the language is not specified, ask before providing code.
  • Stay focused on the Proxy pattern; avoid mixing in other patterns unless directly relevant.

Example application: "lazy loading of large images", language: "Java", proxy_types: "virtual proxy", aspect: "performance"

Follow-up prompts

  • What are the key considerations when deciding between a Proxy and a Decorator?
  • Can you give an example where a Proxy pattern might complicate the design?
  • How do I test a system using a Proxy pattern for reliability?