I had another question here in the same context. Now I have another query.
In NBuilder, FizzWare.NBuilder
namespace contains the interface ISingleObjectBuilder
and class SingleObjectBuilderExtension
which is container of extension methods of ISingleObjectBuilder
.
Now, the extension methods has a generic syntax:
public static ISingleObjectBuilder<T> ExMethod<T,[more types...]>(this ISingleObjectBuilder<T> objectBuilder, [more params])
{
((IObjectBuilder<T>)objectBuilder).ExMethod([more params]);
return objectBuilder;
}
So you can see, although the methods accept ISingleObjectBuilder
, it expects the parameter to be an IObjectBuilder
which is a sub-interface of ISingleObjectBuilder
.
Now consider this senario:
- I have implemented MySingleObjectBuilder:ISingleObjectBuilder.
- In my client code I have using
FizzWare.NBuilder
I can accessMySingleObjectBuilder.ExMethod()
- When I do this, I obviously get an exception because
MySingleObjectBuilder
is not anIObjectBuilder
.
Of course, it would be safer if the Extension Methods were for IObjectBuilder
.
Now the question is, isn't the safer option be better too?