Are there any reasons why you would not use Code Contracts to enforce business rules?
Imagine that you have a User class that represents one user of the system and defines actions that can be performed with other users. You can write a ChangePassword method like this ...
public void ChangePassword(User requestingUser, string newPassword) { Contract.Requires<ArgumentNullException>(requestingUser); Contract.Requires<ArgumentNullException>(newPassword);
Or you can implement a security check as a prerequisite using Contract.Requires ...
public void ChangePassword(User requestingUser, string newPassword) { Contract.Requires<ArgumentNullException>(requestingUser != null); Contract.Requires<ArgumentNullException>(newPassword != null);
What are the advantages and disadvantages of these two methods?
Richard Poole
source share