AlgoMaster Logo
AlgoMasterRefactor a Project Dashboardmedium

Refactor a Project Dashboard

medium

Design and refactor a ProjectDashboard that reports progress for several projects.

Each project owns its tasks. A task has a title, a completed flag, and an archived flag. Archived tasks are historical records: they do not count toward progress and cannot be completed.

The dashboard exposes these operations:

  • createProject(name) stores an empty project and returns its id.
  • addTask(projectId, title, completed, archived) asks that project to add a task and returns the task id, or -1 for an unknown project.
  • completeTask(projectId, taskId) returns false for an unknown project, unknown task, or archived task. Otherwise, it marks the task complete and returns true.
  • progress(projectId) returns "<name>: <completed>/<active>", excluding archived tasks from both numbers, or "UNKNOWN".
  • projectCount() returns the number of projects.

The legacy starter exposes each project's task collection. The dashboard indexes tasks, changes their flags, and calculates progress itself. Because it reaches past the project, it misses the archived-task rule.

Refactor the design so the dashboard talks to projects, and projects own every operation involving their task collection.

Example 1:

Input:

Output:

Explanation: The archived task stays inside the project but does not participate in current progress.

Example 2:

Input:

Output:

Explanation: The dashboard delegates the update and the query to the project that owns the tasks.

Constraints

  • 1 <= name.length, title.length <= 40
  • At most 100 calls will be made across all methods.

Starter Code

The starter compiles, but getTasks turns the project's internal structure into dashboard knowledge and lets archived behavior be bypassed.

How the design is graded

needs 7/10 to pass
  • No exposed task collection

    Full marks when Project owns its task list and ProjectDashboard never retrieves or indexes that collection. Lose points heavily for getTasks, tasks properties or dashboard code that loops over Task objects.

  • Behavior delegated to owners

    Full marks when the dashboard delegates add, complete and progress operations to Project, while archived-task decisions remain inside Project or Task. Lose points when the dashboard checks archived or completed flags itself.

  • Required behavior

    Full marks when archived tasks are excluded from progress and cannot be completed, invalid ids are handled exactly, and successful operations preserve stable ids. Lose points for printing to stdout or returning mutable internals.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new ProjectDashboard()null
createProject("Alpha")0
addTask(0, "Build", false, false)0
addTask(0, "Old plan", true, true)1
progress(0)"Alpha: 0/1"
completeTask(0, 1)false
progress(0)"Alpha: 0/1"
projectCount()1

Archived tasks are neither counted nor mutable through the dashboard.

Run checks these cases. Submit also runs a larger hidden set.