Questions tagged [design-by-contract]

Design by Contract (DbC) or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define formal, precise and verifiable interface specifications for software components, which extend the ordinary definition of abstract data types with preconditions, postconditions and invariants. These specifications are referred to as "contracts", in accordance with a conceptual metaphor with the conditions and

Design by Contract (DbC) or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define formal, precise and verifiable interface specifications for software components, which extend the ordinary definition of abstract data types with preconditions, postconditions and invariants. These specifications are referred to as "contracts", in accordance with a conceptual metaphor with the conditions and obligations of business contracts.

Because Design by Contract is a registered trademark of Eiffel Software in the United States, many developers refer to it as Programming by Contract, Contract Programming, or Contract-First development.

216 questions
0
votes
1 answer

Iterate through a matrix with openJML

I have a class with a matrix initialized with all 0 and 1 in a specific position: public class MatrixTest { /*@ spec_public @*/ int[][] griglia; //@requires true; //@ensures griglia[2][3] == 1; public MatrixTest() { griglia…
gbalduzzi
  • 9,356
  • 28
  • 58
0
votes
1 answer

C4J framework in IDEA

I have the problem with C4J framework. So I have class, for example PhysicsUtils package ua.avereschaka.Utils; import de.vksi.c4j.ContractReference; import…
Artem Vereschaka
  • 125
  • 1
  • 1
  • 9
0
votes
2 answers

Checking preconditions on parameters in public methods

I'm going to ask your Point of view about a design matter. The question is basically the following: a public method of an object should always check preconditions in its input parameters or is it better to love responsibility to the caller and…
0
votes
0 answers

Braced list initialization of a container of abstract class in C++

I would like to do something similar to this: #include #include #include class Abstract { public: virtual void foo() = 0; }; class Concrete : public Abstract { void foo() { std::cout << "foo's implementation"…
Luke Skywalker
  • 1,464
  • 3
  • 17
  • 35
0
votes
1 answer

How to use the method compile in smalltalk and what parameters can I call it with

I'm trying to add additional functionality to the already defined method "compile" in smalltalk. here is the code I wrote: compile: code notifying: requestor trailer: bytes ifFail: failBlock self log:(self substring: code delimiter: $?). super…
Amer Mograbi
  • 489
  • 1
  • 6
  • 18
0
votes
2 answers

How to ensure that implementations of an interface have a connection string if they are backed by a database using code contracts

Imagine you've an interface like this: public interface IPersonManager { public void AddPerson(string name); } ...and an implementation which we'll going to call DefaultPersonManager. Let's say we want to be sure that any implementation of…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
0
votes
1 answer

How to make sure contracts in DbC being tested before rollout?

How do you make sure the contracts you defined for your software components using Design by Contract (DbC) are being tested at some point? Shall I write unit tests for every single contract I define? One benefit I see in DbC vs. isolated testing of…
bastian
  • 1,122
  • 11
  • 23
0
votes
1 answer

Why ContractAnnotationAttribute of ReSharper cannot target constructors?

What is the reason why this static analysis attribute is not allowed to be declared on constructors? I would like to annotate that a constructor throws an exception when a null argument is passed. [AttributeUsage(AttributeTargets.Method,…
Den
  • 1,827
  • 3
  • 25
  • 46
0
votes
1 answer

Cross-interface contracts

I consider interfaces not only as a set of members, but also as a "contract" which force realisation to hold restrictions specified in interface documentation. For example: interface IDevice { bool IsActive { get; } int Address { get; } …
astef
  • 8,575
  • 4
  • 56
  • 95
0
votes
0 answers

Code Contracts Invariant unproven.. Works fine with Contract.Assert at the end of each method

I'm hoping someone can help me.. I have a C# class in which I have implemented a Code Contracts invariant. My methods keep throwing "invariant unproven" errors unless I explicitly assert the invariant is true. My suspicion is that the problem…
krex
  • 345
  • 3
  • 8
  • 21
0
votes
1 answer

Yii: design-by-contract with PHPUnit 3.7

I am using the yii framework and phpunit. I can run phpunit test. But I want to add asserts in my controller like it is described here. I think the class BankAccount is no test. So there must be a way to use the asserts not in tests. If I call…
EvilKarter
  • 267
  • 7
  • 22
0
votes
1 answer

Assertion, Exception, run time error, or Undefined Behaviour?

I am working on a finite state machine library, with these public methods: template void add_state(); // allocate STATE_T on heap - STATE_T must derive from state template
Igneous01
  • 719
  • 1
  • 10
  • 24
0
votes
1 answer

Does LSP also make sense for dynamic typed language like Ruby?

Consider the classic example in Java // Violation of Likov's Substitution Principle class Rectangle { protected int m_width; protected int m_height; public void setWidth(int width){ m_width = width; } public void…
mko
  • 21,334
  • 49
  • 130
  • 191
0
votes
4 answers

Technical term for methods that mutate global state?

Is there a standard technical term for methods that mutate global state? "Unpure" is too strict, because the unpure methods println("I don't consider stdout to be part of the global state") and date() do not modify global state. "Mutator method"…
DaveFar
  • 7,078
  • 4
  • 50
  • 90
0
votes
1 answer

How do I set up Microsoft Contracts static checking in Visual Studio 2010?

I recently downloaded Visual Studio 2010b2, and wanted to re-evaluate some of my questions about the Microsoft contracts static checker. I managed to re-use most of the code by using the System.Diagnostics.Contracts namespace for the code, but I am…
John Gietzen
  • 48,783
  • 32
  • 145
  • 190
1 2 3
14
15