Interfaces, Coupling and What a Module Promises · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Promises your modules keep

Computing · Software Engineering · ages 19-20
Name ______________________   Date ____________
  1. A file prints a banner whenever it is imported. What should happen?

    • Keep it, banners are harmless
    • Move the banner behind the run only guard
    • Delete all functions
  2. What may other code rely on in a module?

    • Only the published names it offers
    • The private helper drafts
    • Every line inside the file
  3. If callers stay on the published surface, the author can rewrite the inside freely.

    Circle one:   True   False

  4. A module reorganizes its internals but keeps published names. Which caller breaks?

    • One reaching past the surface into internals
    • One that never imports it
    • One using only published names
  5. Which import style keeps the module home visible at each use?

    • Copying the class into your file
    • from shapes import Circle
    • import shapes, then shapes.Circle
  6. Two designs differ: one uses shapes.Circle, one digs into helper drafts. Which makes a rename cheaper?

    • The digger, since it knows more
    • The shapes.Circle one, since it rests on the promise
    • Both cost the same
  7. A review finds a caller patching a module private counter to add a feature. What should the review say?

    • Ask for a published hook instead, since the patch couples to insides
    • Forbid all future imports
    • Praise the shortcut
  8. State the promise of a module that mails reports, without describing its inside.

    • It loops rows with an index counter
    • It opens a socket on port 25
    • It sends each report once and reports success or failure
LightMySky · lightmysky.comW1-mt_EUZyD26WFk-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Promises your modules keep W1-mt_EUZyD26WFk-s1

  1. Move the banner behind the run only guard · Importing should deliver names with no side surprises.
  2. Only the published names it offers · The interface is the promise set; the rest may change.
  3. True · The surface is the promise; the inside is free to change.
  4. One reaching past the surface into internals · Past the surface means feeling every internal move.
  5. import shapes, then shapes.Circle · The module name stays in front of every use.
  6. The shapes.Circle one, since it rests on the promise · Resting on the promise shields you from internal renames.
  7. Ask for a published hook instead, since the patch couples to insides · Patching insides buys one feature and sells the next change.
  8. It sends each report once and reports success or failure · A promise names what others may rely on, never how it works.
Worksheet · LightMySky