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
1
vote
0 answers

How can I hide a method with a generic return type from WCF?

I have this scenario (abridged): [ServiceContract] public class TokenProviderService : ITokenProvider { private ITokenProvider TokenProvider { get; set; } // BK - WCF doesn't like generic returns, so I've used an intermediary method. …
ProfK
  • 49,207
  • 121
  • 399
  • 775
1
vote
2 answers

Enforcing and contract methods in Squeak

So I created a class that enforces every method (message) that is sent to it's class instance. i.e that code: |a| a := Animal new. a makeSound: 'bark' should lead to a call to "doesNotUnderstand" (even though it exists in the class) and it should…
wannabe programmer
  • 653
  • 1
  • 9
  • 23
1
vote
1 answer

Shifting from WCF to REST - is it possible to generate proxy classes?

We currently have an application (Client/Server) that communicates through WCF. We would like to move away from the WCF approach and use a REST approach instead. There are a few reasons for this, such as overhead (in terms of size) and the…
ForestC
  • 213
  • 1
  • 12
1
vote
1 answer

How do I get Entity Framework to use interfaces on the generated classes?

I have a project where the client is using Entity Framework, and I'm trying to abstract away the generated classes from the rest of the application. One generated class is Category and it has say Type as a property. I've created an interface that I…
Joseph
  • 25,330
  • 8
  • 76
  • 125
1
vote
2 answers

Difference among goals of DBC, AOP, TDD and Unit tests

I've read about all those approaches: Design by Contract, Aspect Oriented Programming, Test Driven Development and Unit testing. In practice I've used only Unit tests and AOP (AspectJ). I know that that are the different things but seems I've got…
VB_
  • 45,112
  • 42
  • 145
  • 293
1
vote
1 answer

Code Contract and ensuring no exceptions are thrown

I was wondering if I'm able to use Microsoft Code Contracts to verify the invariant that a method shall not throw any exception. The use case is as follows: I have an importer with a logger attached to it, where the importer uses a base class for…
Xilconic
  • 3,785
  • 4
  • 26
  • 35
1
vote
2 answers

Yii: Design-By-Contract with PHPUnit

Why does the call of PHPUnit in the class CTestCase works: require_once('PHPUnit/Autoload.php'); .... PHPUnit_Framework_Assert::assertNotNull($object); But if I call it the same way in a file of components directory it shows…
EvilKarter
  • 267
  • 7
  • 22
1
vote
1 answer

Contracts design pattern in C

Is there a library/framework/article that describes ways to use contracts in C I mean code that is more then obvious asserts for example somting like: Programming with Contracts in C++ but for C
alexpov
  • 1,158
  • 2
  • 16
  • 29
1
vote
2 answers

Design by Contract and Fail Fast

Fail Fast - Fail-fast is a property of a system or module with respect to its response to failures. A fail-fast system is designed to immediately report at its interface any failure or condition that is likely to lead to failure. Fail-fast…
1
vote
2 answers

Design-by-contract support in coffeescript without language extensions

I consider design-by-contract an useful technique and want to apply it to my coffeescript code. There is contracts.coffee, which looks really nice (like Haskell): id :: (Num) -> Num id = (x) -> x Downside is that it is a language extension. I'm…
Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
1
vote
1 answer

How to enforce custom class instance invariants in Java

What is the best way in Java to enforce class instance invariants (i.e. to ensure that certain statements are true right before and after calling any public method)? I will include below an example (the one that has made me wonder about this…
Dušan Rychnovský
  • 11,699
  • 8
  • 41
  • 65
1
vote
2 answers

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
x2.
  • 9,554
  • 6
  • 41
  • 62
1
vote
1 answer

Ways to specify whether a feature is supported in contract

I have an interface -though it could also be an abstract class- that should allow its implementers to specify whether they support a particular feature and I'm looking for the best way to achieve that. There are several choices here: Looking at BCL,…
Şafak Gür
  • 7,045
  • 5
  • 59
  • 96
1
vote
1 answer

ACSL annotations on C macros

Is it possible to annotate C macros with ACSL? eg: /*@ assigns \nothing; behavior xmin: assumes x < y; ensures \result == x; behavior ymin: assumes y <= x; ensures \result == y; disjoint behaviors; …
1
vote
1 answer

PyContract PostCondition Involving non-input-parameter Variable

Hopefully, this will be my last question in the series (my project is almost over, unless the requirements change). I'm working on writing some constraints for a class method using PyContract (not PyContracts). In one of my functions, I have an…
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241