CS FundamentalsVery hardProduct-company design interview
A class Report depends on ReportFormatter, and ReportFormatter depends on Report to read its data, creating a cyclic dependency between their packages. Which design change breaks the cycle in line with the Dependency Inversion Principle?
- A. Merge both packages into one
- B. Make all fields public
- C. Have ReportFormatter depend on an abstraction such as a ReportData interface owned by its own package, which Report implements
- D. Duplicate the formatter code inside Report
Correct answer: C. Have ReportFormatter depend on an abstraction such as a ReportData interface owned by its own package, which Report implements
Introducing an interface and inverting one dependency turns the cycle into a one-way graph (the Acyclic Dependencies Principle). Merging hides the problem; duplication creates another.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A unit test calls a service that reads the current time with datetime.now() and fails every day after 6 pm. What is the cleanest fix?
- How many of these situations can produce a merge conflict when merging branch B into A from their common ancestor O? 1. A and B changed…
- Feature X takes the 'happy path' through 5 screens. An alternate flow can occur at screen 2 (2 variants) and an exception flow at screen 4…
- A mobile app shows the error rate of a new release, rolled out to 10% of users as a canary, at 1.2% against 0.4% for the old version on…
- Assertion (A): A test suite that mocks every collaborator of every class can pass while the integrated system fails. Reason (R): Mocks…
- A single-page app makes 30 sequential API calls to render a dashboard, each taking about 40 ms of network round trip. The team cannot…