Choose Language

Create ⏱ 15 min

Design Tic Tac Toe: Low Level Design Coding Interview Question

What You Will Learn

  • 低レベル設計の基礎を学ぶ
  • クラス図とインターフェースの使い方を理解する
  • ティックタックトゥーのゲームを設計する方法を知る

Key Concepts

  • 低レベル設計では、問題文をコードに変換することが求められる
  • クラス図は、システムの構成要素とその関係を表現するために使用される
  • インターフェースは、クラスやモジュール間の通信を定義するために使用される
  • ゲームを設計する際には、タイムアウト、アンドゥ機能、観戦者機能などを考慮する必要がある
  • システムの拡張性を考慮して、重要なクラスから設計を始めることが重要である

Code Examples

from what we have been talking about in system design till now → システム設計の基礎的な概念を表すコード class diagrams, the interfaces, the designs and so on and so forth → クラス図やインターフェースの使用例 for tic-tac-toe in some time → ティックタックトゥーの設計例 class diagram → クラス図の具体例 for the game, is this going to be a timed game → ゲームのタイムアウト機能の実装例 if it’s actually not exposed to the user because the undo function actually lets you revert a move if there is a failure → アンドゥ機能の実装例 for a game who’s actually not playing the game and will there be any statistics stored for users so this user has played X number of games one Y number of them and therefore is ranked number one in the world now these are the features that we’ll be working on there’s more things of course that you can ask in any game system for example is there any tournament possibility in this system are there going to be some artificial intelligence frameworks used in this system I can think of when I’m playing on chess → ゲームの観戦者機能や統計機能の実装例 with the most important class, in our case it is the game board → ゲームボードクラスの実装例 for this is because you can think of the system, the entire system interacting with this most important class and you can build the solution slowly keeping the whole thing extensible → ゲームボードクラスの重要性を表すコード for the smaller classes, inevitably what you do is you detail them too much while the important, you know, the elephant in the room is being ignored → 小さなクラスの実装例

Lesson Summary

このレッスンでは、低レベル設計の基礎とクラス図の使用方法を学びました。また、ティックタックトゥーのゲームを設計する方法を知り、重要なクラスから設計を始めることの重要性を理解しました。低レベル設計では、問題文をコードに変換することが求められ、クラス図やインターフェースを使用してシステムの構成要素とその関係を表現します。ティックタックトゥーのゲームを設計する際には、タイムアウト、アンドゥ機能、観戦者機能などを考慮する必要があります。システムの拡張性を考慮して、重要なクラスから設計を始めることが重要です。次のレッスンでは、より複雑なシステムの設計方法を学びます。

Practice Exercise

ティックタックトゥーのゲームボードを表すクラスを設計してください。ボードは3x3のマトリックスで、各セルには0、1、または2の値が入っています。0は空のセル、1はプレイヤー1のセル、2はプレイヤー2のセルを表します。ボードクラスには、セルの値を取得および設定するメソッドが必要です。また、ボードの状態を出力するメソッドも必要です。

What Is Next

次のレッスンでは、より複雑なシステムの設計方法を学びます。具体的には、ゲームの観戦者機能や統計機能を実装する方法を知ることになります。