Integrating Transit Modules
A transit information service uses two independently developed modules. Module A provides getRoute(start, end), which returns a list of integer stop IDs. Module B provides printRoute(stopNames), which requires a list of string names to display the route.
A developer writes the following code to integrate the modules, using a helper function getStopName(id) that returns a string:
route <- getRoute(“North”, “South”)
names <- [] ; FOR EACH stop IN route { APPEND(names, getStopName(stop)) } ; printRoute(route)
Assume getRoute(“North”, “South”) returns the list [12, 45] and getStopName correctly returns “Elm” and “Oak”.
If the developer executes this sequence, what data is passed to printRoute and how does it affect the integration?
It passes [], which violates Module B’s interface because the loop fails to modify the route list.
It passes [12, 45], which violates Module B’s interface because it provides integers instead of strings.
It passes [“Elm”, “Oak”], which successfully integrates the modules according to the stated interfaces.
It passes [“Elm”, “Oak”], which violates Module B’s interface because it provides a list instead of a single string.
Question Leaderboard
Not enough data yet to show leaderboard.
