Intermediate 25 min read

Design the Data Structures

By the end of this lesson, you'll be able to:

  • Identify which collection type fits each piece of an employee management problem
  • Sketch the data structures before writing implementation code
  • Apply the collection decision process from Module 16 to a real scenario

Prerequisites: Module 16: "Collections: Sets and Maps"

What we're building

Over this module you'll build a small employee management system that:

  1. Stores employees in a directory, looked up by employee ID.
  2. Deduplicates and validates employee data using Sets.
  3. Generates reports (like headcount by department) from the underlying collections.
  4. Handles edge cases — a missing employee, invalid data — gracefully.

Each lesson builds one piece, reusing the collection and OOP patterns from Modules 10-16.

Applying the decision process

Using Module 16's three-question process on this problem:

  • "Look up an employee by their employee ID." → Map (Map<String, Employee>, direct key lookup).
  • "Track which departments exist, with no duplicates." → Set (Set<String>, uniqueness only).
  • "List every employee in a specific department, in the order they were hired." → List (List<Employee>, order matters).

Each of these was a plain "which collection?" question the moment the actual requirement was written out clearly — the same process from Module 16, just applied to real requirements instead of abstract examples.

Sketching before code

EmployeeDirectory
  - holds: Map<String, Employee> keyed by employee ID
  - responsible for: adding an employee, looking one up, listing all
    department names (deduplicated)

Employee
  - holds: employeeId, name, department, hireDate
  - responsible for: describing itself

Exactly the same "find the nouns, sketch responsibilities" approach from Module 12's "Design the Classes" lesson — now with the added step of naming which collection type each responsibility actually needs.

Exercise

As a comment, decide which collection type fits: "track every unique job title across all employees, order doesn't matter."

Show hint

Uniqueness matters, order doesn't.

APEX

Design the Data Structures Quiz

1. Which collection type fits "look up an employee by their employee ID"?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Before writing any code, this lesson maps out which collection type — List, Set, or Map — fits each piece of an employee management system, using the decision process from Module 16.