Basically I'm looking at 2 different situations:
Method calls within the same class:
public class MyClass
{
public Bar GetDefaultBar(Foo foo)
{
Contract.Requires(foo != null);
return GetSpecificBar(foo, String.Empty);
}
public Bar GetSpecificBar(Foo foo, string name)
{
Contract.Requires(foo != null);
Contract.Requires(name != null);
...
}
}
Method calls within different classes:
public class MyClass
{
private MyBarProvider { get; set; }
public Bar GetDefaultBar(Foo foo)
{
Contract.Requires(foo != null);
return BarProvider.GetSpecificBar(foo, String.Empty);
}
//Object-Invariant ensures that MyBarProvider is never null...
}
public class MyBarProvider
{
public Bar GetSpecificBar(Foo foo, string name)
{
Contract.Requires(foo != null);
Contract.Requires(name != null);
...
}
}
I'm wondering if it is necessary to have duplicate contracts for either of these situations? I'm guessing that there might be a way to avoid it in the first example (all within the same class), but not in the second example (different classes). Also, should I avoid duplicating or should it be in there?