Published Sep 3, 2019

Episode 51: Design By Contract

Explore the transformative programming paradigm of Design by Contract with Arno Schaefer and Michael Stal as they delve into its core concepts, emphasizing the power of preconditions and postconditions in ensuring method reliability, and discuss its practical applications, benefits, and limitations in maintaining robust software systems.
Episode Highlights
Software Engineering Radio - the podcast for professional software developers logo

Popular Clips

Episode Highlights

  • Concept Overview

    Design by Contract, a concept introduced by Bertrand Meyer, revolutionizes how we think about software interfaces. It emphasizes that interfaces are more than just method signatures; they include a set of expectations and guarantees, forming a "contract" between the caller and the object. This paradigm is crucial for ensuring that software components interact predictably and reliably, even if the programming language doesn't explicitly support it.

    The idea is every method on the object guarantees to do something to yield certain results, to make certain modifications. If you as the caller meet your part of the contract, if you meet the preconditions that you.

    ---

    Arno Schaefer explains that while some languages like Eiffel support this concept natively, the mindset itself is beneficial for all developers 1 2 3.

       

    Interface Focus

    Design by Contract shifts the focus from implementation to interface, ensuring that operations are more than just signatures—they are contracts. This approach requires that every subtype maintains at least the same contract as its supertype, promoting consistency and reliability. Preconditions and postconditions operate on parameters and visible state, providing a formal specification of what code does, which is invaluable for maintaining up-to-date documentation.

    The first and biggest benefit is pre and post conditions never get outdated. They're always up to date documentation about what an interface actually does, what operations on the interface do.

    ---

    However, there are limitations, especially in user interfaces where specifying preconditions can be challenging 4 5 6.

Related Episodes