Realization
Realization states that a concrete implementation fulfills an abstraction. In UML, a dashed line with a hollow triangle points from the implementation toward the contract.
What you’ll understand
- Realization states that a concrete implementation fulfills an abstraction. In UML, a dashed line with a hollow triangle points from the implementation toward the contract.
- A sender realizes the delivery contract while the receipt service depends on that contract.
- Evaluate the tradeoff: A diagram documents conformance, but tests must establish behavioral compatibility. Python can express abstract methods; JavaScript commonly uses agreed method shapes.
Useful first: Classes and Objects
The idea and when to recognize it
Realization states that a concrete implementation fulfills an abstraction. In UML, a dashed line with a hollow triangle points from the implementation toward the contract.
- Requirement: A receipt caller must accept multiple sender implementations.
- Change to anticipate: Show that both concrete senders fulfill the same send operation rather than inheriting caller behavior.
- Design goal: A sender realizes the delivery contract while the receipt service depends on that contract.
Start with the concrete problem
A receipt caller must accept multiple sender implementations.
Show that both concrete senders fulfill the same send operation rather than inheriting caller behavior.
| Direct implementation | Revised design |
|---|---|
| Drawing an inheritance line to the caller confuses implementing a contract with specializing an existing implementation. | A sender realizes the delivery contract while the receipt service depends on that contract. |
| The baseline case can hide the problem. Compare the extension and boundary fixtures before accepting this design. | A diagram documents conformance, but tests must establish behavioral compatibility. Python can express abstract methods; JavaScript commonly uses agreed method shapes. |
Responsibilities and contracts
A sender realizes the delivery contract while the receipt service depends on that contract.
- ReceiptService: Depends on the sender contract. Public operations: send(message)
- Sender: Defines message delivery. Public operations: send(message)
- EmailSender: Implements the same contract. Public operations: send(message)
Read the design
Select a participant to inspect its responsibility and public operations. Follow the labeled relationships; an arrow indicates direction, while the legend distinguishes ownership, substitution, and temporary use.
Preparing the design walkthrough…
Follow the interaction
Choose a supplied workload and compare the direct and revised implementations. Step through the same operation in both languages. Object values are recorded after each highlighted statement; previous steps remain unchanged.
Preparing the design walkthrough…
Implementation and expected output
Read the complete example alongside its input and expected output. The implementation selector changes the displayed program; the language selector preserves your current scenario and playback position.
Preparing the design walkthrough…
Try the idea in another setting
A memory repository and a database repository can both realize a persistence contract.
- Name the new client contract before adapting the example.
- Identify which state belongs to each object and who controls its lifetime.
- Write one normal case and one boundary case before extending the design.
Tradeoffs and interview takeaways
A diagram documents conformance, but tests must establish behavioral compatibility. Python can express abstract methods; JavaScript commonly uses agreed method shapes.
Common mistake: Drawing an inheritance line to the caller confuses implementing a contract with specializing an existing implementation.
- Explain the choice: A sender realizes the delivery contract while the receipt service depends on that contract.
- Challenge your choice: A diagram documents conformance, but tests must establish behavioral compatibility. Python can express abstract methods; JavaScript commonly uses agreed method shapes.
- Describe a requirement that would make the simpler implementation sufficient.
Design challenge and knowledge check
Preparing the design walkthrough…