[ OK ]11b5121d-455e-4796-bdce-4aae60438deb — full content available
[ INFO ]category: Coding difficulty: medium freq: Must first seen: 2026-03-13
[MEDIUM][CODING][MUST]
$catproblem.md
The Chat Bot System Refactoring is a common OpenAI coding interview question that tests Object-Oriented Programming (OOP) design, clean code principles, and the ability to extend legacy logic. ShowOffer +1 056
Problem Statement Overview
You are typically given a legacy codebase for a chat service that supports multiple types of bots (e.g., AwayBot, MeetBot, TacoBot) triggered by specific slash commands or keywords. 一亩三分地 1
The initial implementation is usually "smelly"—relying on a single massive class with nested if-else or switch statements to handle different bot types and commands. 一亩三分地 2
The Task
You must refactor the code to achieve the following:
Decoupling: Separate the message processing logic from the individual bot behaviors.
Extensibility: Make it easy to add new bots (e.g., a WeatherBot) without modifying the core message-routing engine.
Command Handling: Implement a clean way to register and execute "slash commands" (like /away or /meet). 一亩三分地 +2
Key Technical Challenges
Interfaces & Polymorphism: Defining a common Bot interface or abstract class so the main system can interact with any bot through a standard processMessage() method.
Registry Pattern: Implementing a mechanism (often a Map) to register bots and their associated commands for quick lookup.
Message Parsing: Efficiently identifying if a message is a command or a regular chat and routing it to the correct handler.
Concurrency: Handling multiple chat sessions or concurrent messages, which may require thread-safe data structures. 一亩三分地 +1
Evaluation Criteria
Interviewers at OpenAI evaluate this problem based on:
Code Quality: Is the code readable, modular, and "production-ready"?
Trade-offs: Can you explain why you chose a specific pattern (e.g., Strategy vs. Factory)?
Communication: Do you talk through your refactoring strategy before writing code? YouTube +2
Would you like to see a Python or Java implementation of the refactored patterns for this specific problem?