C44 · Topic 3.14 · 40 minutes · AAP-3.D
Replace an implementation without changing callers
By the end you can:
- Separate a contract from its implementation.
- Detect a compatibility-breaking update.
- Justify reuse using evidence and integration tests.
Before this lesson: topics 3.12, 3.13.
- Library
- A collection of procedures available for reuse.
- API
- An interface describing how software components can be used.
Understand
If two implementations satisfy the same documented contract, a caller can often use either without knowing the internal algorithm. This separates what a procedure promises from how it is implemented. Changes to a contract, however, can break callers even when the procedure name stays the same.
Evaluate practical trade-offs: supported platforms, documentation, maintenance, licensing and resource use. A version update deserves tests; a change from inclusive to exclusive limits is observable behaviour, not merely a faster internal implementation.
Worked example
A text library documents normalise(text): trim leading/trailing spaces, convert ASCII A–Z to a–z, leave internal spaces and other characters unchanged.
- normalise(" RED Bus ") returns "red bus".
- normalise("A B") returns "a b", with two internal spaces.
- A replacement that collapses internal spaces violates this contract, even if it looks cleaner.
Explore each concept
Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.
- Documented arguments, ranges and returns
- Implementation versus interface
- Integration and version tests
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Value (0–10)5Waiting
- Minimum (0–10)5Waiting
- VersioncompatibleWaiting
Ready to explore: Library contract and compatible replacement
Why: Change an input, predict the first effect, then advance one step.
Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.
Step through and experiment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Input 1 A B Waiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Try internal double spaces, only spaces and non-ASCII letters.
Check a misconception
Claim: A new library version is interchangeable if its procedure names are unchanged.
Names can remain while argument meanings, returns or edge cases change. Compare documented behaviour and test callers.
Guided practice
Write a test that exposes a replacement that removes all spaces instead of trimming only the ends.
Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.
Independent transfer
A library update changes clamp to reject values outside the interval instead of returning the boundary. Explain the impact on an existing caller passing 14 with bounds 0…10.
Exit check
What evidence supports replacing the internal implementation while keeping callers unchanged?
Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.
Check yourself
Your practice so far
Check an answer to see its rationale.