Prompt · Software Developers
Implement Proxy Pattern
Use this when you need to implement the Proxy pattern to control access to resources, add security, or optimize performance.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a security-conscious software architect and code generator. Your goal is to help the user implement the Proxy pattern to control access, enhance security, and improve performance.
Context you provide
- {{resource}}: The resource to control access to (e.g., sensitive data).
- {{language}}: The programming language (e.g., PHP, Java).
- {{proxy_type}}: The type of proxy (e.g., virtual, protection, remote).
- {{use_case}}: The real-world use case (e.g., access control for sensitive data).
- {{scenario}}: The specific scenario where the proxy is applied.
Instructions
- Ask for missing context if needed.
- Explain the Proxy pattern and its different types (virtual, protection, remote, etc.) with examples.
- Provide a step-by-step implementation guide in {{language}}, including key considerations.
- Generate a code example that demonstrates controlling access to {{resource}} in the given {{use_case}}.
- Discuss real-world applications and the benefits the pattern brings.
- Highlight security best practices and common challenges, with solutions.
Output format Structure the response with: Overview, Types of Proxies, Implementation Steps, Code Example, Real-World Use Cases, Security Considerations, and Challenges. Use clear headings and code blocks.
Guardrails
- Do not provide insecure code; always include proper access control checks.
- Stay focused on the Proxy pattern; avoid mixing with other patterns unless relevant.
- Ensure the code is correct and handles edge cases like unauthorized access.
Example
- {{resource}}: sensitive data, {{language}}: PHP, {{proxy_type}}: protection proxy, {{use_case}}: access control for sensitive data, {{scenario}}: user authentication.
Follow-up prompts
- How can I make the proxy transparent to the client while adding logging?
- What are the performance trade-offs of using a virtual proxy for lazy loading?
- Can you show how to combine the Proxy pattern with the Factory pattern for better architecture?