Design communication handler and exceptions

Quick Overview

This question evaluates object-oriented design, API and state management skills along with exception handling and identity-based reasoning by requiring implementation of a single-connection communication handler and a custom CommunicationException; it belongs to the System Design domain and emphasizes practical implementation details rather than purely conceptual theory. Such questions are commonly asked to assess a candidate's ability to enforce invariants, manage limited resources and error conditions in a mutable service interface, and demonstrate practical coding-level design and testing of runtime behaviors.

Design communication handler and exceptions

Company: Akuna Capital

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: Take-home Project

Create two classes: ( 1) CommsHandler(CommsHandlerABC), an abstract base class with methods connect(self, user1: Caller, user2: Caller) -> str, hangup(self, user1: Caller, user2: Caller) -> str, and clear_all(self) -> None. Behavior: connect establishes a connection and stores the two callers; if user1 is user2, raise CommunicationException with the message "{user1.name} cannot connect with {user2.name}!"; if user1 and user2 are different and the communication line is already in use, raise CommunicationException with "Connection in use. Please try later"; otherwise store the connected users and return "Connection established between {user1.name} and {user2.name}". Behavior: hangup ends the connection if user1 and user2 are currently communicating; if user1 is user2, raise CommunicationException with "{user1.name} cannot hangup with {user2.name}"; if user1 and user2 are different and communicating, disconnect them and return "{user1.name} and {user2.name} are disconnected"; if they are not communicating, raise CommunicationException with "{user1.name} and {user2.name} not found in the communication channel". Behavior: clear_all clears the communication channel regardless of current users. ( 2) CommunicationException(Exception): accepts an error message in its constructor and is raised as specified. Assume class Caller is already implemented. Provide class definitions and brief tests or examples.

Quick Answer: This question evaluates object-oriented design, API and state management skills along with exception handling and identity-based reasoning by requiring implementation of a single-connection communication handler and a custom CommunicationException; it belongs to the System Design domain and emphasizes practical implementation details rather than purely conceptual theory. Such questions are commonly asked to assess a candidate's ability to enforce invariants, manage limited resources and error conditions in a mutable service interface, and demonstrate practical coding-level design and testing of runtime behaviors.

|Home/System Design/Akuna Capital
Akuna Capital logo
Akuna Capital
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerTake-home ProjectSystem Design
3
0

Implement a Communication Handler with Exceptions

Context

You are building a single-line communication handler that can connect exactly two Caller instances at a time. The environment already provides:

  • Caller: a class with at least a .name attribute (assume implemented elsewhere).
  • CommsHandlerABC: an abstract base class specifying the interface for a communication handler.

Your task is to implement a concrete CommsHandler subclass that enforces the specified behaviors and to define a custom CommunicationException.

Requirements

Classes to Implement

  1. CommsHandler(CommsHandlerABC)
    • Methods to implement:
      • connect(self, user1: Caller, user2: Caller) -> str
      • hangup(self, user1: Caller, user2: Caller) -> str
      • clear_all(self) -> None
    • Behavior:
      • connect:
        • If user1 is user2, raise CommunicationException with the exact message: "{user1.name} cannot connect with {user2.name}!"
        • If user1 and user2 are different and the communication line is already in use, raise CommunicationException with: "Connection in use. Please try later"
        • Otherwise, store the two connected users and return: "Connection established between {user1.name} and {user2.name}"
      • hangup:
        • If user1 is user2, raise CommunicationException with: "{user1.name} cannot hangup with {user2.name}"
        • If user1 and user2 are different and are currently communicating, disconnect them and return: "{user1.name} and {user2.name} are disconnected"
        • If they are not communicating, raise CommunicationException with: "{user1.name} and {user2.name} not found in the communication channel"
      • clear_all:
        • Clear the communication channel regardless of current users (no return value).
  2. CommunicationException(Exception)
    • Accepts an error message in its constructor and is raised as specified.

Notes

  • Use identity checks (is) when comparing callers (i.e., same object instance), not name equality.
  • The handler supports only one active connection at a time.
  • Provide brief tests or usage examples demonstrating the specified behaviors.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...