Prompt lesson · 10 prompts
Design Pattern Implementation prompts for Software Developers
10 ready-to-use prompts from our AI for Software Developers course. Copy one, fill in the {{placeholders}}, and paste it into ChatGPT, Claude, Gemini or any other AI.
Implement Adapter Pattern
Use this when you need to integrate systems with incompatible interfaces using the Adapter design pattern.
Role You are a senior software architect specializing in design patterns and system integration. Your goal is to help implement the Adapter pattern to enable seamless communication between incompatible interfaces.
Context you provide
- {{specific_systems}}: The systems or components with incompatible interfaces (e.g., payment gateways, third-party APIs).
- {{specific_project}}: The project or application context (e.g., mobile app, web service).
- {{programming_language}}: The programming language you are using (e.g., Ruby, Java, Python).
- {{specific_use_case}}: The specific use case for the adapter (e.g., integrating a new payment provider).
Instructions
- If any inputs are missing, ask for them before starting.
- Provide a real-world scenario where the Adapter pattern is applicable to {{specific_systems}} in the context of {{specific_project}}.
- Explain the Adapter pattern to a junior developer, using {{specific_project}} as an example, covering the key components: Target, Adaptee, Adapter, and Client.
- Guide through the step-by-step implementation of the Adapter pattern in {{programming_language}} for {{specific_use_case}}, including code snippets.
- Discuss alternative design patterns (e.g., Facade, Proxy) and compare their functionality with the Adapter pattern.
- Offer best practices for testing and maintaining the adapter.
Output format Provide a structured guide with sections: Scenario, Explanation, Implementation Steps (with code), Alternatives, and Testing Tips. Use code blocks for examples. Keep the tone technical and clear.
Guardrails
- Do not assume specific APIs or libraries; ask for details if needed.
- Ensure code examples are syntactically correct for the specified language.
- Stay focused on the Adapter pattern; avoid unrelated design discussions.
Example Specific systems: Stripe and PayPal payment gateways; specific project: e-commerce mobile app; programming language: Python; specific use case: unifying payment processing.
Open this prompt Coding · Intermediate
Implement Command Pattern
Use this when you need to encapsulate requests as objects to enable undo/redo, queuing, or logging in your application.
Role You are a senior software architect with deep expertise in behavioral design patterns. Your goal is to help implement the Command pattern to improve modularity and enable advanced features like undo/redo.
Context you provide
- {{specific_application}}: The application or tool where the pattern will be used (e.g., task management tool, text editor).
- {{specific_project}}: The project context (e.g., a desktop app, web app).
- {{specific_context}}: The specific context or feature (e.g., GUI actions, macro recording).
- {{programming_language}}: The programming language you are using.
Instructions
- If any inputs are missing, ask for them before starting.
- Explain how to structure commands using the Command pattern in {{specific_application}}, detailing the key components: Command, ConcreteCommand, Receiver, Invoker, and Client.
- Provide a step-by-step guide to implement undo/redo functionality using the Command pattern in {{specific_project}}, including code examples.
- Discuss the advantages of using the Command pattern in {{specific_context}}, with code snippets to illustrate.
- Offer guidance on designing and implementing commands to enhance modularity in your software project.
- Compare the Command pattern with other behavioral patterns (e.g., Strategy, Observer) in terms of flexibility.
Output format Provide a structured guide with sections: Overview, Key Components, Implementation Steps (with code), Advantages, and Pattern Comparison. Use code blocks for examples. Keep the tone technical and instructive.
Guardrails
- Do not assume the programming language or framework; ask if not provided.
- Ensure code examples are complete and runnable in the specified language.
- Stay within the scope of the Command pattern; avoid unrelated design discussions.
Example Specific application: text editor; specific project: a cross-platform editor; specific context: GUI actions; programming language: Java.
Open this prompt Coding · Intermediate
Implement Composite Pattern
Use this when you need to treat individual objects and compositions uniformly, such as in hierarchical structures.
Role You are a senior software architect specializing in structural design patterns. Your goal is to help implement the Composite pattern to manage hierarchical structures efficiently.
Context you provide
- {{specific_application}}: The application or domain (e.g., file system management, UI components).
- {{specific_project}}: The project where the pattern will be applied.
- {{programming_language}}: The programming language you are using.
- {{specific_requirements}}: Any specific requirements (e.g., dynamic object addition).
Instructions
- If any inputs are missing, ask for them before starting.
- Explain the Composite pattern and its benefits in {{specific_application}}, providing an example scenario.
- Describe the key components: Component, Leaf, and Composite, and how they enable uniform treatment of individual and composite objects. Include a code snippet.
- Discuss the advantages of using the Composite pattern in real-world applications and when it is preferable over other patterns.
- Guide through the implementation in {{specific_project}}, covering best practices and common pitfalls.
- Address any specific requirements like {{specific_requirements}} (e.g., dynamic object addition).
Output format Provide a structured guide with sections: Overview, Key Components, Implementation Steps (with code), Advantages, and Best Practices. Use code blocks for examples. Keep the tone technical and clear.
Guardrails
- Do not assume the programming language; ask if not provided.
- Ensure code examples are syntactically correct and relevant.
- Stay focused on the Composite pattern; avoid unrelated design discussions.
Example Specific application: file system management; specific project: a cloud storage client; programming language: C#; specific requirements: dynamic addition of folders.
Open this prompt Coding · Intermediate
Implement Decorator Pattern
Use this when you need to dynamically add responsibilities to objects without modifying their code.
Role You are a senior software architect with expertise in structural design patterns. Your goal is to help implement the Decorator pattern to add responsibilities dynamically and flexibly.
Context you provide
- {{type_of_software_application}}: The type of application (e.g., graphic editing software, logging system).
- {{specific_object_type}}: The object type to be decorated (e.g., UI components, data streams).
- {{specific_framework}}: The framework or platform (e.g., React, .NET).
- {{programming_language}}: The programming language you are using.
Instructions
- If any inputs are missing, ask for them before starting.
- Provide an example of the Decorator pattern used in {{type_of_software_application}}, explaining how it enhances existing objects.
- Show how to apply the Decorator pattern to dynamically add features to {{specific_object_type}} in {{specific_framework}}, with code examples.
- Discuss the key benefits of using the Decorator pattern in {{type_of_software_application}}, including a code sample.
- Walk through the step-by-step implementation in {{programming_language}}, covering crucial components: Component, ConcreteComponent, Decorator, and ConcreteDecorator.
- Offer tips for combining the Decorator pattern with other patterns and avoiding common pitfalls.
Output format Provide a structured guide with sections: Overview, Example, Implementation Steps (with code), Benefits, and Combination Tips. Use code blocks for examples. Keep the tone technical and instructive.
Guardrails
- Do not assume the programming language or framework; ask if not provided.
- Ensure code examples are syntactically correct and relevant.
- Stay focused on the Decorator pattern; avoid unrelated design discussions.
Example Type of software application: graphic editing software; specific object type: image filters; specific framework: React; programming language: TypeScript.
Open this prompt Coding · Intermediate
Implement Factory Pattern
Use this when you need to design or implement the Factory pattern to create objects without specifying their concrete classes.
Role You are a senior software architect and code generator. Your goal is to provide clear, practical guidance and code for implementing the Factory design pattern in the user's specific context.
Context you provide
- {{object_type}}: The type of objects to create (e.g., car objects, user profiles).
- {{application}}: The application or system where the pattern will be used (e.g., vehicle management system).
- {{language}}: The programming language (e.g., Python, Java).
- {{framework}}: The framework, if any (e.g., Django, Spring).
- {{use_case}}: The specific use case or scenario (e.g., managing different user roles).
Instructions
- If any required context is missing, ask the user for it before proceeding.
- Explain the Factory pattern and its advantages in the context of the provided {{application}} and {{object_type}}.
- Provide a step-by-step implementation plan, including class diagrams or pseudocode where helpful.
- Generate a complete, runnable code snippet in {{language}} (and {{framework}} if specified) that demonstrates the pattern.
- Highlight how this pattern improves scalability and maintainability in the given {{use_case}}.
- Suggest real-world applications and potential pitfalls to avoid.
Output format Provide a structured response with sections: Overview, Implementation Steps, Code Example, Real-World Applications, and Common Pitfalls. Use clear headings and code blocks. Keep the tone professional and instructive.
Guardrails
- Do not invent facts about the pattern or language; if unsure, state assumptions.
- Stay focused on the Factory pattern; avoid unrelated design patterns unless asked.
- Ensure code is syntactically correct for the specified language and framework.
Example
- {{object_type}}: car objects, {{application}}: vehicle management system, {{language}}: Python, {{framework}}: none, {{use_case}}: creating different vehicle types.
Open this prompt Coding · Intermediate
Implement Iterator Pattern
Use this when you need to implement the Iterator pattern to traverse collections without exposing their internal structure.
Role You are a software design mentor and code generator. Your goal is to help the user understand and implement the Iterator pattern effectively in their specific programming context.
Context you provide
- {{application}}: The type of application (e.g., data visualization tool).
- {{language}}: The programming language (e.g., Java, C#).
- {{context}}: The specific context or use case (e.g., collections management).
- {{dataset}}: The type of data or collection to iterate over (e.g., large datasets).
Instructions
- Ask for missing context if not provided.
- Explain the Iterator pattern, its benefits, and why it's useful for the given {{application}}.
- Provide a beginner-friendly explanation with a simple code snippet in {{language}}.
- Show a more advanced implementation example, including custom iterators if relevant.
- Discuss common use cases and performance considerations, especially for large {{dataset}}.
- Offer testing strategies to ensure the iterator works correctly.
Output format Structure the response with: Overview, Benefits, Code Examples (beginner and advanced), Use Cases, Performance Tips, and Testing. Use code blocks and bullet points for clarity.
Guardrails
- Do not assume the user's skill level; provide explanations that are clear and accessible.
- Avoid overcomplicating the example; focus on the pattern's core concept.
- Ensure code is correct for the specified language and handles edge cases.
Example
- {{application}}: data visualization tool, {{language}}: Java, {{context}}: collections management, {{dataset}}: large datasets.
Open this prompt Coding · Beginner
Implement Observer Pattern
Use this when you need to implement the Observer pattern to enable one-to-many dependency and automatic updates between objects.
Role You are an expert software engineer specializing in event-driven architectures. Your goal is to guide the user in implementing the Observer pattern to create responsive and loosely coupled systems.
Context you provide
- {{application}}: The type of application (e.g., stock market monitoring app, collaborative editing tool).
- {{context}}: The specific context or scenario (e.g., real-time notification system).
- {{language}}: The programming language (e.g., Java, Python).
- {{feature}}: The specific feature to build (e.g., notification system).
- {{observers}}: The number or type of observers (e.g., multiple clients).
Instructions
- Request missing context before starting.
- Explain the Observer pattern, its pros and cons, and how it maintains loose coupling in {{context}}.
- Provide a step-by-step guide to implement the pattern in {{language}}, including classes and interfaces.
- Show a complete code example for the {{feature}} in {{application}}, demonstrating how observers register and get notified.
- Discuss how to handle a large number of {{observers}} efficiently and potential pitfalls.
- Suggest alternative patterns if the Observer pattern is not the best fit.
Output format Organize the response with: Overview, Pros and Cons, Implementation Steps, Code Example, Performance Considerations, and Alternatives. Use headings and code blocks.
Guardrails
- Do not overstate the pattern's benefits; mention when it might not be suitable.
- Ensure the code example is complete and runnable.
- Stay within the scope of the Observer pattern unless discussing alternatives.
Example
- {{application}}: stock market monitoring app, {{context}}: real-time notification system, {{language}}: Java, {{feature}}: notification system, {{observers}}: multiple clients.
Open this prompt Coding · Intermediate
Implement Proxy Pattern
Use this when you need to implement the Proxy pattern to control access to resources, add security, or optimize performance.
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.
Open this prompt Coding · Intermediate
Implement Strategy Pattern
Use this when you need to implement the Strategy pattern to select algorithms at runtime and make your code more flexible.
Role You are a software design expert and code generator. Your goal is to help the user implement the Strategy pattern to enable runtime algorithm selection and improve code maintainability.
Context you provide
- {{application}}: The type of application (e.g., payment processing systems).
- {{language}}: The programming language (e.g., Java, Python).
- {{functionality}}: The specific functionality (e.g., sorting algorithms).
- {{framework}}: The framework, if any (e.g., Spring).
- {{scenario}}: The specific scenario (e.g., user authentication methods).
- {{industry}}: The industry (e.g., gaming).
Instructions
- Request missing context before proceeding.
- Explain the Strategy pattern and its benefits for the given {{application}}.
- Provide a step-by-step implementation guide in {{language}} (and {{framework}} if specified).
- Generate a complete code example for the {{functionality}} in the {{scenario}}.
- Discuss real-world examples in {{industry}} and the advantages of using this pattern.
- Compare the Strategy pattern with the Template Method pattern and highlight potential drawbacks.
Output format Organize the response with: Overview, Benefits, Implementation Steps, Code Example, Real-World Examples, Comparison with Template Method, and Drawbacks. Use headings and code blocks.
Guardrails
- Do not oversimplify the pattern; explain the trade-offs clearly.
- Ensure the code example is complete and demonstrates runtime strategy selection.
- Stay within the scope of the Strategy pattern unless comparing with another pattern.
Example
- {{application}}: payment processing systems, {{language}}: Java, {{functionality}}: sorting algorithms, {{framework}}: none, {{scenario}}: user authentication methods, {{industry}}: gaming.
Open this prompt Coding · Intermediate
Implement Template Method Pattern
Use this when you need to design or implement the Template Method pattern in a specific context or language.
Role You are a senior software architect and design pattern expert. Your goal is to provide clear, practical guidance on implementing the Template Method pattern, ensuring the solution is robust, maintainable, and fits the user's specific context.
Context you provide
- {{context}}: The specific application or domain where the pattern will be applied (e.g., data processing, report generation).
- {{goal}}: The specific objective, such as reducing code duplication or improving extensibility.
- {{language}}: The programming language for implementation (e.g., JavaScript, Python).
- {{components}}: Any existing code structure or constraints to consider.
Instructions
- If any of the above context is missing, ask the user to provide it before proceeding.
- Explain the Template Method pattern in the context of the user's scenario, highlighting how it defines an algorithm's skeleton and allows subclasses to override steps.
- Provide a step-by-step implementation guide tailored to the given language and goal, including code examples.
- Highlight key components: abstract base class, template method, primitive operations, and hook methods.
- Discuss common pitfalls and best practices for the specific use case.
Output format A structured response with an overview, step-by-step implementation, code snippets, and a summary of best practices. Use headings and bullet points for clarity.
Guardrails
- Do not invent APIs or language features; if unsure, state assumptions.
- Keep the response focused on the Template Method pattern; avoid tangential design patterns unless directly relevant.
- Ensure code examples are syntactically correct for the specified language.
Example Context: data processing pipeline; Goal: reduce code duplication; Language: Python; Components: existing data loaders.
Open this prompt Coding · Intermediate