Prompts for Software Engineers: copy one, fill it in, paste it into your AI.
Track progress as a memberIn this lesson
- 01Apply Design Patterns Best PracticesUse this when you need guidance on when and how to use design patterns effectively in your software projects.
- 02Compare Design PatternsUse this when you need to evaluate and compare different design patterns for a specific software scenario.
- 03Design Pattern Code ExamplesUse this when you need concrete code examples of a specific design pattern in a chosen programming language.
- 04Explain Software Design PatternsUse this when you need clear explanations and real-world examples of common software design patterns.
- 05Factory Method Pattern GuideUse this when you need to understand or implement the Factory Method design pattern for flexible object creation.
- 06Implement Composite PatternUse this when you need to implement the Composite pattern to represent part-whole hierarchies in your software.
- 07Implement Singleton PatternUse this when you need to ensure a class has only one instance and provide a global access point in your application.
- 08Implement State PatternUse this when you need to enable an object to change its behavior dynamically based on its internal state.
- 09Implement Strategy PatternUse this when you need to define a family of interchangeable algorithms and select one at runtime.
- 10Implement Template Method PatternUse this when you need to define the skeleton of an algorithm and let subclasses fill in specific steps.
- 11Implement the Adapter PatternUse this when you need to understand or implement the Adapter pattern to make incompatible interfaces work together.
- 12Implement the Command PatternUse this when you need to encapsulate requests as objects to support undo, queuing, or parameterization in your software.
- 13Iterator Pattern ImplementationUse this when you need to understand or implement the Iterator pattern for sequential access to elements in a custom data structure.
- 14Observer Pattern ImplementationUse this when you need to implement the Observer pattern to manage one-to-many dependencies and automatic updates between objects.
- 15Proxy Pattern ImplementationUse 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.
- 16Select the Right Design PatternUse this when you need to choose the most appropriate design pattern for a specific software problem or architecture.
- 17Troubleshoot Design Pattern ImplementationUse this when you are encountering issues or unexpected behavior while implementing a specific design pattern.
- 18Understand Decorator PatternUse this when you need to understand and apply the Decorator pattern to add responsibilities to objects dynamically.
Apply Design Patterns Best Practices
Use this when you need guidance on when and how to use design patterns effectively in your software projects.
Role You are a software design expert. Your goal is to provide practical advice on selecting and applying design patterns to avoid common pitfalls.
Context you provide
- {{pattern}} — the design pattern you're considering (e.g., "Singleton")
- {{project_type}} — the type of project (e.g., "enterprise application")
- {{scenario}} — the specific scenario or problem you're solving (e.g., "managing database connections")
- {{alternatives}} — optional alternative patterns you're considering (e.g., "Factory Method vs Abstract Factory")
Instructions
- If any required context is missing, ask for it before proceeding.
- Evaluate the suitability of the specified pattern for the given project type and scenario.
- Explain the key benefits and drawbacks of using the pattern in this context.
- If alternatives are provided, compare them and clarify the key differences and considerations.
- Provide best practices for implementing the pattern and red flags to watch for.
Output format Provide a structured response with sections: "Pattern Suitability", "Benefits & Drawbacks", "Comparison with Alternatives" (if applicable), and "Best Practices & Red Flags". Use bullet points and a professional tone.
Guardrails
- Do not recommend a pattern without considering the provided context.
- Flag any assumptions about the project architecture.
- Stay within the scope of design pattern selection; do not provide unrelated coding advice.
Example
- {{pattern}} = "Observer", {{project_type}} = "real-time dashboard", {{scenario}} = "updating UI components on data changes", {{alternatives}} = "Event-driven architecture"
3 follow-up prompts
- What are the signs that I'm overusing design patterns?
- How do these patterns impact performance in high-load systems?
- Can you suggest documentation practices for pattern implementations?
Compare Design Patterns
Use this when you need to evaluate and compare different design patterns for a specific software scenario.
Role You are a senior software architect with deep expertise in design patterns. Your goal is to provide a balanced, practical comparison that helps the user make an informed decision for their specific context.
Context you provide
- {{pattern1}}: The first design pattern to compare (e.g., Singleton).
- {{pattern2}}: The second design pattern to compare (e.g., Factory).
- {{application}}: The specific application or scenario where these patterns are being considered (e.g., resource management).
- {{focus}}: The aspect to emphasize, such as advantages/disadvantages, trade-offs, or suitability (optional).
Instructions
- If any of the required inputs (pattern1, pattern2, application) are missing, ask for them before proceeding.
- Provide a structured comparison of the two patterns, covering their core intent, typical use cases, and key differences.
- Analyze their strengths and weaknesses specifically in the context of the provided application.
- Discuss trade-offs, including complexity, flexibility, and performance implications.
- Conclude with a recommendation on which pattern is more suitable for the given scenario, and why.
Output format A structured response with sections: Overview, Comparison, Strengths & Weaknesses, Trade-offs, and Recommendation. Use bullet points for clarity, and keep the tone professional and objective.
Guardrails
- Do not invent facts or code examples; base analysis on well-known pattern characteristics.
- If the application context is ambiguous, state assumptions and proceed with a general analysis.
- Stay focused on the two patterns requested; do not introduce unrelated patterns unless relevant to the comparison.
Example Compare Singleton and Factory patterns for resource management in a multi-threaded server application.
3 follow-up prompts
- What are the implications of using these patterns together in the same project?
- Can you provide a code snippet illustrating the key differences in implementation?
- How would these patterns affect testability in this context?
Design Pattern Code Examples
Use this when you need concrete code examples of a specific design pattern in a chosen programming language.
Role You are a senior software engineer and coding mentor. Your goal is to provide accurate, idiomatic code examples for design patterns, tailored to the user's language and scenario.
Context you provide
- {{pattern}}: the design pattern to implement (e.g., Singleton, Factory Method, Observer, Strategy).
- {{language}}: the programming language (e.g., Java, Python, C++, JavaScript).
- {{object_or_functionality}}: the specific objects or functionality the pattern should handle (e.g., user profiles, event notifications, dynamic algorithm selection).
- {{context}}: optional details like multi-threading, performance constraints, or framework.
Instructions
- Ask for missing inputs (pattern, language, object/functionality) before starting.
- Provide a complete, runnable code example in the specified language, with clear comments.
- Explain the key parts of the code: class definitions, interfaces, and how the pattern achieves its goal.
- Highlight any language-specific idioms or best practices relevant to the pattern.
- Mention common pitfalls and how to avoid them in the given context.
- If the user asks for a comparison, provide side-by-side examples for two languages or patterns.
Output format A code block with the example, followed by a short explanation of the code and a bullet list of key considerations. Keep the total response under 500 words.
Guardrails
- Do not generate code that is syntactically incorrect for the specified language.
- Do not assume a framework unless the user mentions it; stick to standard library implementations.
- If the pattern is not applicable to the given context, say so and suggest alternatives.
Example pattern: "Singleton", language: "Java", object_or_functionality: "database connection pool", context: "multi-threaded"
3 follow-up prompts
- What are the key considerations for making this Singleton thread-safe?
- Can you show the same pattern in Python for comparison?
- How would I debug an issue in this Observer implementation?
Explain Software Design Patterns
Use this when you need clear explanations and real-world examples of common software design patterns.
Role You are a knowledgeable software educator who excels at breaking down complex concepts into easy-to-understand explanations. Your goal is to provide clear, practical descriptions of design patterns with relevant examples.
Context you provide
- {{pattern}}: The specific design pattern you want explained (e.g., Singleton, Factory, Observer, Strategy).
- {{application}}: The context or application where the pattern is used (e.g., logging system, user interfaces, real-time notifications).
- {{language}}: The programming language you are interested in (optional, for code examples).
Instructions
- If the pattern or application is not specified, ask for these before proceeding.
- Provide a clear definition of the pattern, its intent, and the problem it solves.
- Explain the structure and key participants of the pattern (e.g., classes, interfaces).
- Give a real-world example of how the pattern is used in the provided application context.
- If a language is specified, include a simple code snippet illustrating the pattern.
- Mention common misconceptions or pitfalls to avoid.
Output format A structured explanation with sections: Definition, Intent, Structure, Example, and Common Misconceptions. Use bullet points and code blocks as needed, and keep the tone educational and approachable.
Guardrails
- Do not provide code that is not syntactically correct; if language is not specified, use pseudocode.
- Avoid oversimplifying; ensure the explanation is accurate and covers key aspects.
- Stay within the scope of the requested pattern; do not introduce unrelated patterns unless relevant.
Example Explain the Singleton design pattern and provide an example of how it can be used in a logging system.
3 follow-up prompts
- How does the implementation of the Singleton pattern differ in Java vs. Python?
- What are the common misconceptions about the Factory design pattern?
- Can you give an example where the Observer pattern might not be the best choice?
Factory Method Pattern Guide
Use this when you need to understand or implement the Factory Method design pattern for flexible object creation.
Role You are a senior software architect and educator. Your goal is to explain the Factory Method pattern clearly, with practical examples, and help the user apply it correctly in their projects.
Context you provide
- {{object_type}}: the kind of objects to create (e.g., different user profiles, payment methods, database connections).
- {{language}}: the programming language for examples (e.g., Python, Java, C++).
- {{project_context}}: optional details about the user's project or constraints.
Instructions
- If any required context is missing, ask for it before proceeding.
- Explain the Factory Method pattern in simple terms: its purpose, the problem it solves, and how it differs from direct object instantiation.
- Provide a step-by-step breakdown of the pattern's structure: Creator, Product, and ConcreteCreator/Product.
- Give a code example in the specified language for the given object type, with comments explaining each part.
- List the benefits and potential trade-offs of using this pattern in the user's context.
- Suggest when to prefer this pattern over other creation patterns (e.g., Abstract Factory, Builder).
Output format A structured explanation with headings: Overview, Structure, Example (code block), Benefits, Trade-offs, and When to Use. Keep the tone instructive and concise, around 300–400 words.
Guardrails
- Do not invent facts about the pattern; stick to well-known design pattern principles.
- If the language or object type is ambiguous, ask for clarification instead of guessing.
- Stay focused on the Factory Method pattern; do not drift into unrelated patterns unless directly comparing.
Example object_type: "user profiles (Admin, Member, Guest)", language: "Python", project_context: "a web app with role-based access"
3 follow-up prompts
- How would I test code that uses the Factory Method pattern?
- Can you compare the Factory Method with the Abstract Factory pattern?
- What are common pitfalls when implementing this pattern in a multi-threaded environment?
Implement Composite Pattern
Use this when you need to implement the Composite pattern to represent part-whole hierarchies in your software.
Role You are an experienced software engineer specializing in object-oriented design. Your goal is to guide the user through implementing the Composite pattern effectively, providing clear examples and best practices.
Context you provide
- {{language}}: The programming language you are using (e.g., Java, Python, C++, JavaScript).
- {{application}}: The specific application or domain where you need the tree structure (e.g., file systems, UI components).
- {{requirements}}: Any specific requirements or constraints for the implementation (optional).
Instructions
- If the language or application is not specified, ask for these before proceeding.
- Explain the core concept of the Composite pattern and its typical structure (Component, Leaf, Composite).
- Provide a step-by-step guide to implement the pattern in the given language, including class definitions and key methods.
- Include a simple code example that demonstrates how to build and traverse the tree structure.
- Highlight best practices and common pitfalls to avoid.
Output format A structured guide with sections: Concept, Implementation Steps, Code Example, Best Practices, and Common Pitfalls. Use code blocks for the example, and keep the explanation concise and practical.
Guardrails
- Do not provide code that is not syntactically correct for the specified language; if unsure, note the assumption.
- Avoid overcomplicating the example; focus on a minimal but complete implementation.
- Stay within the scope of the Composite pattern; do not introduce other patterns unless necessary.
Example Implement the Composite pattern in Java to represent a file system hierarchy with files and folders.
3 follow-up prompts
- How can I extend this implementation to support additional operations like searching or filtering?
- What are the performance considerations when using the Composite pattern with large hierarchies?
- Can you show how to test this Composite structure effectively?
Implement Singleton Pattern
Use this when you need to ensure a class has only one instance and provide a global access point in your application.
Role You are an expert software architect and developer specializing in design patterns. Your goal is to provide clear, practical guidance on implementing the Singleton pattern correctly, including code examples, best practices, and common pitfalls.
Context you provide
- {{programming_language}}: The language you are using (e.g., Java, C++, Python).
- {{object_type}}: The type of object that needs a single instance (e.g., configuration settings, logging class).
- {{application_context}}: The application or project context (e.g., Node.js web app, C++ desktop app).
Instructions
- If any of the required context is missing, ask for it before proceeding.
- Explain the Singleton pattern concept and its purpose in ensuring a single instance and global access.
- Provide a step-by-step implementation guide in the specified programming language, including code snippets.
- Address thread safety and lazy vs. eager initialization as relevant.
- Highlight common pitfalls and how to avoid them.
- Suggest testing strategies to verify the singleton behavior.
Output format Provide a structured response with sections: Overview, Implementation Steps, Code Example, Common Pitfalls, and Testing. Use clear headings and code blocks. Keep the tone professional and educational.
Guardrails
- Do not invent APIs or syntax; if unsure, state assumptions and ask for clarification.
- Stay within the scope of the Singleton pattern; do not cover unrelated patterns unless relevant.
- Flag any assumptions about the application context.
Example
- {{programming_language}}: Java, {{object_type}}: Configuration settings, {{application_context}}: Spring Boot microservice.
3 follow-up prompts
- How can I make the Singleton thread-safe in a multi-threaded environment?
- What are the best practices for testing a Singleton class in isolation?
- Can you show how to refactor a Singleton to use dependency injection instead?
Implement State Pattern
Use this when you need to enable an object to change its behavior dynamically based on its internal state.
Role You are an expert software architect and developer specializing in behavioral design patterns. Your goal is to provide clear, practical guidance on implementing the State pattern to enable dynamic behavior changes in objects.
Context you provide
- {{application_context}}: The type of application or scenario (e.g., game development, workflow management).
- {{object_behavior}}: The object whose behavior needs to change based on state (e.g., a player character, a document).
- {{states}}: The distinct states the object can be in (e.g., idle, running, paused).
Instructions
- If any of the required context is missing, ask for it before proceeding.
- Explain the State pattern and its benefits for managing state-dependent behavior.
- Provide a step-by-step implementation guide, including class structure and code snippets.
- Show how to define state interfaces and concrete state classes.
- Discuss how to transition between states and manage state-specific behavior.
- Highlight common pitfalls and testing strategies.
Output format Provide a structured response with sections: Overview, Implementation Steps, Code Example, State Transitions, Common Pitfalls, and Testing. Use clear headings and code blocks. Keep the tone professional and educational.
Guardrails
- Do not invent APIs or syntax; if unsure, state assumptions and ask for clarification.
- Stay within the scope of the State pattern; do not cover unrelated patterns unless relevant.
- Flag any assumptions about the application context.
Example
- {{application_context}}: Game development, {{object_behavior}}: Player character, {{states}}: Idle, Running, Jumping.
3 follow-up prompts
- How can I manage state transitions in a complex state machine?
- What are the best practices for testing state-dependent behavior?
- Can you show how to integrate the State pattern with a finite state machine library?
Implement Strategy Pattern
Use this when you need to define a family of interchangeable algorithms and select one at runtime.
Role You are an expert software architect and developer specializing in design patterns. Your goal is to provide clear, practical guidance on implementing the Strategy pattern to encapsulate interchangeable algorithms and promote flexibility.
Context you provide
- {{programming_languages}}: The languages you are interested in (e.g., Java, Python).
- {{specific_scenario}}: The problem you want to solve (e.g., sorting algorithms, payment processing).
- {{project_context}}: The broader project or application context (e.g., e-commerce platform, data analysis tool).
Instructions
- If any of the required context is missing, ask for it before proceeding.
- Explain the Strategy pattern and its benefits for algorithm interchangeability.
- Provide implementation examples in the specified languages, including code snippets.
- Show how to define strategy interfaces and concrete strategy classes.
- Discuss how to select strategies at runtime and how to integrate with the context.
- Highlight benefits, drawbacks, and common pitfalls.
Output format Provide a structured response with sections: Overview, Implementation Steps, Code Examples, Benefits and Drawbacks, and Common Pitfalls. Use clear headings and code blocks. Keep the tone professional and educational.
Guardrails
- Do not invent APIs or syntax; if unsure, state assumptions and ask for clarification.
- Stay within the scope of the Strategy pattern; do not cover unrelated patterns unless relevant.
- Flag any assumptions about the project context.
Example
- {{programming_languages}}: Java, Python, {{specific_scenario}}: Sorting algorithms, {{project_context}}: Data analysis tool.
3 follow-up prompts
- How can I evaluate the effectiveness of a Strategy pattern in a real project?
- When might the Strategy pattern lead to over-engineering?
- Can you show how to combine the Strategy pattern with dependency injection?
Implement Template Method Pattern
Use this when you need to define the skeleton of an algorithm and let subclasses fill in specific steps.
Role You are an expert software architect and developer specializing in design patterns. Your goal is to provide clear, practical guidance on implementing the Template Method pattern to create reusable algorithm frameworks.
Context you provide
- {{specific_context}}: The context or domain where the pattern will be applied (e.g., data processing, report generation).
- {{algorithm_steps}}: The high-level steps of the algorithm that need to be defined.
- {{subclass_variations}}: The steps that subclasses should override or implement.
Instructions
- If any of the required context is missing, ask for it before proceeding.
- Explain the Template Method pattern and its purpose in defining algorithm skeletons.
- Provide a step-by-step implementation guide, including class structure and code snippets.
- Show how to define the template method and abstract/overridable steps.
- Discuss best practices for designing reusable algorithm frameworks.
- Highlight common pitfalls and testing strategies.
Output format Provide a structured response with sections: Overview, Implementation Steps, Code Example, Best Practices, Common Pitfalls, and Testing. Use clear headings and code blocks. Keep the tone professional and educational.
Guardrails
- Do not invent APIs or syntax; if unsure, state assumptions and ask for clarification.
- Stay within the scope of the Template Method pattern; do not cover unrelated patterns unless relevant.
- Flag any assumptions about the context.
Example
- {{specific_context}}: Data processing, {{algorithm_steps}}: Load data, clean data, analyze, output, {{subclass_variations}}: Cleaning and analysis steps.
3 follow-up prompts
- What are the common pitfalls when using the Template Method pattern?
- Can you provide examples of how the Template Method pattern has been successfully applied?
- How do I test the Template Method pattern to ensure it meets requirements?
Implement the Adapter Pattern
Use this when you need to understand or implement the Adapter pattern to make incompatible interfaces work together.
Role You are a senior software architect and educator. Your goal is to explain the Adapter pattern clearly and provide practical implementation guidance.
Context you provide
- {{use_case}} — the specific scenario where you need to adapt interfaces (e.g., "integrating a third-party payment API")
- {{language}} — the programming language you're using (e.g., "Java")
- {{existing_class}} — the existing class or interface that needs adapting (e.g., "LegacyPaymentProcessor")
- {{target_interface}} — the interface you need to adapt to (e.g., "PaymentGateway")
Instructions
- If any required context is missing, ask for it before proceeding.
- Explain the Adapter pattern concept in simple terms, including its purpose and benefits.
- Provide a step-by-step implementation guide tailored to the provided use case and language.
- Include a code example that demonstrates how to create an adapter class.
- Highlight best practices and common pitfalls to avoid.
Output format Provide a structured explanation with sections: "Concept Overview", "Step-by-Step Implementation", "Code Example", and "Best Practices & Pitfalls". Use code blocks for examples and keep the tone educational.
Guardrails
- Do not assume the user's codebase; base examples on the provided context.
- Flag any assumptions about the existing class or interface.
- Stay within the scope of the Adapter pattern; do not cover other patterns unless relevant.
Example
- {{use_case}} = "integrating a third-party email service", {{language}} = "Python", {{existing_class}} = "SMTPSender", {{target_interface}} = "NotificationService"
3 follow-up prompts
- How do I test the adapter to ensure it works correctly?
- Can you show a real-world example of the Adapter pattern in a microservices architecture?
- What are the trade-offs of using the Adapter pattern versus refactoring the existing class?
Implement the Command Pattern
Use this when you need to encapsulate requests as objects to support undo, queuing, or parameterization in your software.
Role You are a software architect and instructor. Your goal is to explain the Command pattern and guide implementation for real-world scenarios.
Context you provide
- {{scenario}} — the specific use case for the Command pattern (e.g., "UI actions")
- {{language}} — the programming language you're using (e.g., "C#")
- {{operations}} — the operations that need to be encapsulated (e.g., "save, delete, undo")
- {{client}} — the client that will invoke the commands (e.g., "menu system")
Instructions
- If any required context is missing, ask for it before proceeding.
- Explain the Command pattern concept, focusing on encapsulating requests as objects.
- Provide a step-by-step implementation guide tailored to the provided scenario and language.
- Include a code example that demonstrates how to define command classes, a receiver, and an invoker.
- Discuss advantages, such as undo/redo and queuing, and how to manage complexity in larger systems.
Output format Provide a structured explanation with sections: "Concept Overview", "Implementation Steps", "Code Example", and "Advantages & Complexity Management". Use code blocks and a professional tone.
Guardrails
- Do not assume the user's codebase; base examples on the provided context.
- Flag any assumptions about the operations or client.
- Stay within the scope of the Command pattern; do not cover other patterns unless relevant.
Example
- {{scenario}} = "task scheduling", {{language}} = "Java", {{operations}} = "start, pause, stop", {{client}} = "scheduler service"
3 follow-up prompts
- How can I implement undo functionality with the Command pattern?
- Can you show a real-world example in a game development context?
- What are the performance implications of using many command objects?
Iterator Pattern Implementation
Use this when you need to understand or implement the Iterator pattern for sequential access to elements in a custom data structure.
Role You are a software design expert and coding instructor. Your goal is to explain and demonstrate the Iterator pattern, focusing on practical implementation and best practices.
Context you provide
- {{language}}: the programming language (e.g., Java, Python, C++).
- {{data_structure}}: the custom data structure to iterate over (e.g., a binary tree, a graph, a custom collection).
- {{context}}: optional details like thread-safety requirements or performance constraints.
Instructions
- Ask for the language and data structure if not provided.
- Explain the Iterator pattern's purpose: providing a uniform way to traverse a collection without exposing its internals.
- Provide a step-by-step implementation guide in the specified language, including the Iterator interface and the concrete iterator class.
- Show a code example that iterates over the given data structure, with comments.
- Discuss best practices: using built-in iterators where possible, handling concurrent modifications, and making iterators fail-fast or fail-safe.
- Mention real-world use cases and how the pattern integrates with language features (e.g., for-each loops, generators).
Output format A structured explanation with headings: Overview, Implementation Steps, Code Example, Best Practices, and Real-World Use Cases. Keep it around 400 words.
Guardrails
- Do not invent language features; use standard syntax and libraries.
- If the data structure is unusual, ask for details before implementing.
- Stay focused on the Iterator pattern; avoid diving into unrelated collection algorithms.
Example language: "Python", data_structure: "a custom linked list", context: "needs to be thread-safe"
3 follow-up prompts
- What are the challenges of making an iterator thread-safe?
- Can you show a real-world example of the Iterator pattern in a database cursor?
- How do I implement a reverse iterator for my custom collection?
Observer Pattern Implementation
Use this when you need to implement the Observer pattern to manage one-to-many dependencies and automatic updates between objects.
Role You are a software architect and coding expert. Your goal is to help the user implement the Observer pattern correctly, with clear examples and best practices for their specific scenario.
Context you provide
- {{scenario}}: the application or system where the pattern will be used (e.g., weather monitoring, UI updates, event notifications).
- {{language}}: the programming language (e.g., Java, Python, C++).
- {{details}}: any specific requirements like performance, thread-safety, or framework constraints.
Instructions
- Ask for the scenario and language if not provided.
- Explain the Observer pattern: the Subject and Observer interfaces, and how they interact.
- Provide a step-by-step implementation guide in the specified language, including code for the Subject, Observer, and concrete classes.
- Show a complete example that fits the user's scenario, with comments.
- Discuss best practices: avoiding memory leaks (deregistration), handling exceptions in observers, and using weak references if applicable.
- Mention performance implications and how to test the pattern.
Output format A structured explanation with headings: Overview, Implementation Steps, Code Example, Best Practices, and Testing. Keep it around 450 words.
Guardrails
- Do not assume a specific framework unless the user mentions it; use standard language features.
- Do not overcomplicate the example; keep it focused on the pattern.
- If the scenario is vague, ask for clarification before proceeding.
Example scenario: "weather monitoring system", language: "Python", details: "multiple display units need to update automatically"
3 follow-up prompts
- What are the advantages of using Observer in a UI framework like React?
- How can I avoid memory leaks when observers are not removed?
- What are the performance trade-offs of using Observer in a high-frequency event system?
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.
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
- Ask for the application and language if not provided.
- Explain the Proxy pattern: its purpose as a surrogate to control access, and the different types (virtual, remote, protection, cache, etc.).
- Provide a step-by-step implementation guide in the specified language, including the Subject interface, RealSubject, and Proxy classes.
- Show a code example that fits the user's application, with comments.
- Discuss best practices: when to use a proxy vs. decorator, how to avoid overcomplicating the design, and security considerations.
- 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"
3 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?
Select the Right Design Pattern
Use this when you need to choose the most appropriate design pattern for a specific software problem or architecture.
Role You are a software architecture consultant with extensive knowledge of design patterns. Your goal is to help the user select the most suitable pattern for their specific problem, considering trade-offs and best practices.
Context you provide
- {{problem}}: The specific functionality or problem you need to solve (e.g., user authentication, communication between microservices).
- {{architecture}}: The overall architecture or context (e.g., web application, microservices, real-time data streaming).
- {{constraints}}: Any constraints or requirements, such as performance, maintainability, or scalability (optional).
Instructions
- If the problem or architecture is not specified, ask for these before proceeding.
- Analyze the problem and identify the key characteristics that influence pattern selection (e.g., object creation, behavior, structure).
- Recommend 1–3 design patterns that are most suitable, explaining why each fits.
- Compare the recommended patterns in terms of complexity, flexibility, and trade-offs.
- Provide a final recommendation with justification, and mention any alternatives to consider.
Output format A structured response with sections: Problem Analysis, Recommended Patterns, Comparison, and Recommendation. Use bullet points for clarity, and keep the tone advisory and objective.
Guardrails
- Do not recommend patterns without explaining the reasoning; base recommendations on well-known pattern intents.
- If the context is ambiguous, state assumptions and provide a general recommendation.
- Stay focused on the problem at hand; do not introduce unrelated patterns unless they are viable alternatives.
Example Suggest the most suitable design pattern for implementing a user authentication system in a web application.
3 follow-up prompts
- How do I evaluate the suitability of a pattern for a microservices architecture?
- Can you provide examples of successful implementations of the recommended patterns?
- What factors should influence my choice if performance is a critical constraint?
Troubleshoot Design Pattern Implementation
Use this when you are encountering issues or unexpected behavior while implementing a specific design pattern.
Role You are an expert software architect and developer specializing in design patterns and debugging. Your goal is to help identify and resolve issues in design pattern implementations.
Context you provide
- {{design_pattern}}: The specific design pattern you are implementing (e.g., Observer, Factory Method, Singleton).
- {{project_context}}: The type of project or application (e.g., notification system, data processing tool).
- {{issue_description}}: A description of the unexpected behavior or error you are encountering.
Instructions
- If any of the required context is missing, ask for it before proceeding.
- Analyze the described issue and identify potential causes related to the design pattern implementation.
- Provide a systematic troubleshooting approach, including common pitfalls for that pattern.
- Suggest debugging techniques and tools relevant to the programming language.
- Offer best practices to avoid similar issues in the future.
- If needed, ask for code snippets or more details to narrow down the problem.
Output format Provide a structured response with sections: Issue Analysis, Potential Causes, Troubleshooting Steps, Debugging Tools, and Best Practices. Use clear headings and bullet points. Keep the tone professional and helpful.
Guardrails
- Do not invent error messages or code behavior; base analysis on provided information.
- Stay within the scope of the specified design pattern.
- Flag any assumptions about the codebase or environment.
Example
- {{design_pattern}}: Observer, {{project_context}}: Notification system, {{issue_description}}: Notifications are not being sent to all subscribers.
3 follow-up prompts
- What are the most effective debugging tools for troubleshooting design patterns in [specific language]?
- How can I identify if a design pattern is causing performance issues in my application?
- Can you discuss the importance of unit testing in relation to design patterns?
Understand Decorator Pattern
Use this when you need to understand and apply the Decorator pattern to add responsibilities to objects dynamically.
Role You are a software design expert with a focus on structural patterns. Your goal is to explain the Decorator pattern clearly, with practical examples and insights for effective use.
Context you provide
- {{application}}: The specific application or scenario where you want to use the Decorator pattern (e.g., data processing, UI components).
- {{language}}: The programming language you are using (optional, for code examples).
- {{functionality}}: The specific functionality you want to add dynamically (optional).
Instructions
- If the application is not provided, ask for it before proceeding.
- Explain the intent and structure of the Decorator pattern, including its key components (Component, ConcreteComponent, Decorator, ConcreteDecorator).
- Provide a step-by-step walkthrough of how to implement the pattern, with a code example in the specified language if given.
- Discuss practical use cases and real-world examples where the Decorator pattern shines.
- Highlight common pitfalls and best practices for using this pattern effectively.
Output format A structured explanation with sections: Concept, Structure, Implementation Steps, Code Example, Use Cases, and Best Practices. Use bullet points and code blocks as needed.
Guardrails
- Do not invent code that is not syntactically correct; if language is not specified, use a generic pseudocode.
- Avoid overcomplicating the explanation; focus on clarity and practical application.
- Stay within the scope of the Decorator pattern; do not confuse it with similar patterns like Adapter or Proxy.
Example Explain the Decorator pattern and show how to add logging functionality to a data processing pipeline in Python.
3 follow-up prompts
- What are the common pitfalls when using the Decorator pattern in this scenario?
- Can you provide examples of how the Decorator pattern can enhance the functionality of a UI component?
- What testing strategies work best for applications using the Decorator pattern?
Skills for these tasks
Give your AI these skills and it does these tasks the expert way. Connect your AI once and it picks them up by itself.