AlgoMaster Logo
AlgoMasterNarrow Report Dependencieseasy

Narrow Report Dependencies

easy

Refactor a small report workspace without changing its behavior.

The workspace has two clients of the same in-memory store:

  • an importer that only writes report text;
  • a preview pane that only reads report text.

The starter gives both clients a broad ReportStore interface containing read and write. It works, but each client depends on an operation it never uses.

Keep these behaviors unchanged:

  • importText(text) replaces the stored text, increments the import count, and returns true.
  • preview() increments the preview count and returns "PREVIEW: <current text>".
  • importCount() and previewCount() return their respective counts.

Split the storage contract so each client receives only what it needs. The concrete in-memory store may implement both focused interfaces.

How the design is graded

needs 7/10 to pass
  • Client-focused interfaces

    Full marks when reading and writing are separate contracts, ReportImporter depends only on writing, and PreviewPane depends only on reading. Lose points heavily when either client still receives the broad ReportStore interface.

  • Capability composition

    Full marks when the in-memory store implements both focused contracts and the workspace passes each client only the capability it needs. Lose points for duplicating storage or copying the text between clients.

  • Preserved behavior

    Full marks when imports replace the stored text, previews use the latest text, and both counters are accurate. Lose points for extra prefixes, exceptions, or printed output.

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 ReportWorkspace()null
preview()"PREVIEW: "
importText("Quarterly results")true
preview()"PREVIEW: Quarterly results"
importCount()1
previewCount()2

The preview reads the current text, while the importer replaces it.

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