Oddity Knowledge Base Development guide

Eiffel Development and Practical Design by Contract

5 min read Practical knowledge from OddityRead the article

Eiffel is an object-oriented programming language with a particular emphasis on making software responsibilities explicit. Its Design by Contract approach gives developers a way to state what an operation expects and what it promises. For a business application, that can help turn an informal rule into something developers can inspect, discuss and check.

The value depends on the quality of those rules. A program can faithfully implement the wrong requirement. Before selecting Eiffel or extending an existing Eiffel system, identify the business decisions the software must enforce and the people who can confirm that those decisions are correct.

Start with a rule people understand

Consider a hypothetical training company allocating seats in classroom sessions. A session has a capacity and a count of confirmed attendees. Staff need to accept valid bookings, prevent overbooking and explain when a request cannot be fulfilled. This is a useful starting point because the expected behavior can be stated without discussing a programming language.

Eiffel's general language overview describes features including classes, static typing and automatic memory management. Classes can model concepts such as a session or booking, while routines provide operations on them. These mechanisms organize the implementation; they do not decide whether the training company's capacity policy is sensible.

Separate the policy from the screen

Write down whether staff may reserve provisional seats, whether cancellations release capacity immediately and whether a waiting list counts toward the limit. Put the agreed rules in the application model rather than duplicating them across screens. A booking created through an import should obey the same policy as one entered by a receptionist.

Use contracts to clarify responsibilities

The official Design by Contract introduction explains preconditions, postconditions and class invariants. A precondition states an obligation on the caller. A postcondition describes the result promised after a valid call. An invariant expresses consistency requirements for a class at the relevant externally visible boundaries.

In the session example, an internal operation might require a positive number of seats and sufficient remaining capacity. After successful completion, the confirmed count should increase by the requested amount. The model's consistency rules can describe the permitted relationship between confirmed attendance and capacity. These statements give a reviewer concrete questions to ask about the code.

EiffelStudio offers configurable runtime assertion monitoring. Record which checks the deployed build actually enables. A written assertion and an assertion checked during execution are different kinds of evidence; neither establishes that every important requirement has been captured.

Handle ordinary rejection as ordinary behavior

A full session is an expected business outcome. Check the request at the application boundary and return a useful explanation before calling an internal routine whose precondition requires available seats. Do not make a raw contract failure the normal customer experience. The interface also needs authorization checks so an otherwise valid booking cannot be changed by the wrong person.

If two requests compete for the last seat, a local check alone may be insufficient. Coordinate the check and update through the application's concurrency and persistence design. A contract describes the intended relationship; it does not automatically make separate database operations atomic.

Keep reusable behavior consistent

Eiffel supports inheritance, and its inheritance tutorial explains how inherited contracts shape related classes. When extending a class, review the promises its callers already rely on. A new specialized session type should not unexpectedly invalidate ordinary booking behavior without a deliberate change to the model.

For example, an online session may have a different capacity policy from a classroom session. Decide whether that is a configurable rule or a genuinely different abstraction. Reusing code is helpful only if the shared meaning remains clear. Avoid adding a hierarchy merely because two screens look similar.

Also inspect library assumptions. Eiffel's void-safe project guidance describes configuration and library considerations for avoiding calls on void references. Review the actual project settings and dependencies, especially in older applications. Protection against that class of error does not establish correct scheduling, permissions or database behavior.

Test the outcomes the contracts cannot invent

AutoTest in EiffelStudio supports creating, managing and executing tests. Check its availability for the project's target environment. Use tests that represent meaningful scenarios: reserving the final seat, cancelling a booking, changing capacity and rejecting a request that exceeds the limit.

The documentation on generated tests describes another way to exercise routines. Generated cases can supplement deliberately chosen examples, but they do not know the training company's unwritten policies. Review what is being checked and add explicit cases for rules supplied by staff.

Include integration checks for persistence and notifications. A correct in-memory count is not enough if a restart loses the booking or a failed email leaves staff unsure whether it exists. Confirm that the stored record, the staff view and the customer response agree about the outcome.

Choose a maintainable scope

For an existing Eiffel application, preserve the source, build configuration and dependencies needed to reproduce it. Establish a working baseline before changing the compiler, libraries or business rules. Keep technical upgrades and policy changes distinguishable so a failed test can be investigated without guessing which change caused it.

For new work, evaluate the available maintainers, required integrations and deployment process alongside the language's features. Begin with one bounded workflow, such as session booking, and demonstrate both successful and rejected operations. The useful result is software whose responsibilities can be explained and verified, supported by a team that can keep those responsibilities accurate as the business changes.

Oddity Support

How can we help?

Oddity Data Updates

Know when fresh data arrives.

Receive occasional notices about new and substantially updated database releases. No third-party mailing list.

Oddity Software

Details