DDD Step By Step
A Practical Guide to Domain Driven Design
Code Contracts Primer – Part 5: Utilizing Object Invariants by Derik Whittaker
If you are not familiar with the Code Contracts library which is coming out of Microsoft R&D labs, you need to check this pretty cool little library out.  As of Vs2010/.Net 4.0 this library will be making the jump out of the R&D labs.  Over the next few blog posts we will be taking a look at the topics below. Downloading and setting up the contracts library Handling Legacy Code Providing Support for Unit Tests Utilizing Pre & Post Conditions Utilizing Object Invariants (this post) Performing checking in base classes/abstract classes In this post we are going to take a look at what I think is one of the coolest features of the Contracts Library.  The concept of Object Invariants. What is Object Invariant validation? This part of the library ensures that when the state of an object is changed that the object remains in valid state.  If the state of the object is to become invalid then your contract would fail and this would be an issue. Imagine you have a class called ReportCard, this class is used by a timekeeping system and is used to store instances of daily report cards (a daily report card holds the time/hours worked for that employee).  We want to setup a rule which says that depending on the Read More...

Read the complete post at http://feedproxy.google.com/~r/Devlicious/~3/BqfgRpmLeaQ/code-contracts-primer-part-5-utilizing-object-invariants.aspx


Posted Wed, Jul 1 2009 9:03 AM by DDD Feeds