Archicise
Exercise

Design a Plugin-Based Text Editor

Apply the Open/Closed Principle and plugin architecture patterns to design a text editor whose core is stable and all features are added via plugins.

Functional Requirements

  • Core editing: insert, delete, select, copy, paste
  • Plugin system for extending functionality (syntax highlighting, spell check, auto-complete, git blame)
  • Undo/redo history
  • Multiple open files with tabs
  • Command palette for plugin-contributed commands

Design Challenges

  • Design a stable plugin API that doesn't break with core changes
  • Apply the Visitor or Decorator pattern for text transformations
  • Use the Mediator pattern for plugin-to-plugin communication

Questions to Consider

  • How do plugins subscribe to editor events without tight coupling?
  • How do you prevent a poorly written plugin from crashing the editor?
  • How do you version the plugin API for backward compatibility?
Your Solution

Core Editor Model

Design the core TextDocument (buffer, cursor, selection) and EditorView classes. Apply the MVC pattern: EditorController handles commands, TextDocument is the model, EditorView renders state. Keep the core free of any feature-specific logic.