-
Book Overview & Buying
-
Table Of Contents
C# Programming Cookbook
By :
If you use abstract classes in your code, you will know that being able to control how they are used with code contracts will result in more robust code. But how exactly can we use code contracts with abstract classes? Especially since abstract classes are supposed to contain no implementation? Well, it is definitely possible, and here is how we do it.
If you have not worked with abstract classes before, we advise you to first read Chapter 2, Classes and Generics, to familiarise yourself with how abstract classes are used and created.
Before you go on, ensure that you have added the code contracts using statement to the top of your Recipes.cs class file:
using System.Diagnostics.Contracts;
Create an abstract class called Shape that defines two methods called Length() and Width() which each take an integer value as a parameter. Remember that abstract classes contain no implementation:
public abstract class Shape
{
public abstract...