Using code contracts on abstract classes
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.
How to do it…
- Before you go on, ensure that you have added the code contracts
usingstatement to the top of your
using System.Diagnostics.Contracts; ...