No Interface Without Contract? – Part 5: Using Microsoft Code Contracts

Microsoft Code Contracts? Get started using them!

In the previous part we had a first look on Microsoft Code Contracts. This part will help us getting started using them.

Download and Installation

To use MS Code Contracts you need at least the Standard Edition of Visual Studio 2008 (VS 2010 is also supported).

Read the rest of this entry »

Advertisements

No Interface Without Contract? – Part 4: Writing down Pre- and Postconditions

Contracts are important – we already saw this. What can we do that we always see them when coding?

In the previous part, we formulated pre- and postconditions for a sample class. However, we only have written them down in plain text.

So we are now finding out how to specify them in a more comfortable (and elegant of course 😉 ) way.

I will introduce five possibilities: Documentation, Exception / Assert based, Custom Checker Class, Attributes and Code Contracts.

Read the rest of this entry »

No Interface Without Contract? – Part 3: Finding Pre- and Postconditions

“If you give me a string not beeing null or empty, I will give you a number greater zero” – Pre- and Postconditions made easy.

In the previous part, we found out that pre- and postconditions improve the quality of our code.

Note: I primary announced that part 3 is about writing them down. However, while writing I realized that it is better to split up this part.

Example

Let’s take a look at our sample class first:

Read the rest of this entry »

No interface without contract? – Part 2: About Pre- and Postconditions

Pre- and Postconditions: What they are, why you should use them and how they help you.

In the last part, the result was that we need something helping us to specify those kinds of “Implementation-Requirements”.

I already alluded to Pre- and Postconditions.

Read the rest of this entry »