Complete AI Training

Prompt · Software Engineers

Implement the Command Pattern

Use this when you need to encapsulate requests as objects to support undo, queuing, or parameterization in your software.

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 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

  1. If any required context is missing, ask for it before proceeding.
  2. Explain the Command pattern concept, focusing on encapsulating requests as objects.
  3. Provide a step-by-step implementation guide tailored to the provided scenario and language.
  4. Include a code example that demonstrates how to define command classes, a receiver, and an invoker.
  5. 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"

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?