Design PowerPoint with classes for image/text, modify & undo operations

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-02-04

Problem Statement

Design a PowerPoint-like presentation application where users can create slides, add text and images, modify elements, and perform undo/redo operations. Focus is on object-oriented design, modularity, and applying design patterns.


Functional Requirements


1.Slide Management
•Users can create, delete, and reorder slides.
2.Content Elements
•Slides can contain multiple elements:
•TextBox → text content with font, color, position.
•Image → image content with size, position, and optional metadata.
•Users can add, modify, or delete elements on a slide.
3.Undo / Redo Operations
•Support undoing and redoing actions such as add, modify, delete elements.
•Actions should be tracked per slide and globally.
4.Modification Operations
•Update text content, font, color, or position.
•Update image size, position, or replace image.
5.Optional Features
•Export slides to PDF or images.
•Support multiple users editing (collaboration).
•Layer management (bring forward, send backward).


Non-Functional Requirements


•Extensibility: Easy to add new element types (shapes, charts, videos).
•Efficiency: Undo/redo should be efficient even with many slides and elements.
•Thread Safety: Optional if multi-threaded editing is supported.


Edge Cases & Constraints


•Undo when no previous action → handle gracefully.
•Modify or delete a non-existent element → throw error.
•Undo/redo stack size → can be bounded for memory efficiency.


Design Hints


•Key Classes / Interfaces:
•Presentation → contains multiple Slide objects.
•Slide → contains multiple SlideElement objects.
•SlideElement → abstract class/interface with common properties like position and size.
•TextBox → inherits SlideElement.
•Image → inherits SlideElement.
•Command → interface for actions (AddElementCommand, DeleteElementCommand, ModifyElementCommand).
•CommandManager → manages undo/redo stacks.
•Design Patterns:
•Command Pattern → encapsulate actions for undo/redo.
•Composite Pattern → treat slide elements uniformly in a hierarchy.
•Observer Pattern (Optional) → notify UI components of changes.


Example Flow


1.User adds a TextBox → AddElementCommand.execute() → added to slide and pushed to undo stack.
2.User moves the text box → ModifyElementCommand.execute() → update element and push command to stack.
3.User clicks undo → CommandManager.undo() → revert last action.
4.User clicks redo → CommandManager.redo() → reapply the action.


Evaluation Areas


•Correct OOP modeling of slides and elements.
•Efficient and clean undo/redo mechanism using Command pattern.
•Extensibility to support new element types and operations.
•Handling edge cases and command stack management.


This LLD problem tests OOP design, design pattern application (Command, Composite), and modular system design for a real-world productivity application.

Solution

Comments