C# – Has anyone used a Stub in production code

cstub

I have a situation where some procedure returns an object (kind of like a DTO) with a certain interface:

interface ISomeInterface
{
    string StringReadOnlyProperty { get; }
    int IntReadWriteProperty { get; set; }
}

(In the real implementation, there are more properties).

There are two different places where these objects are handled – one process that generates new instances, and another process that manipulates existing instances. Internally, these two implementations are very different. The "new" instance is just a stub, and the "existing" instance has lots of tracking logic.

So I need to have this "Stub" implementation kicking around all the time. I was thinking about how nicely Rhino Mocks can stub up implementations of an interface without having to generate a concrete class. Has anyone ever used a "stubbing" mechanism like Rhino Mocks, but in their production code rather than in their unit tests? It just seems like a bad practice, because of the dependency to a testing framework.

Best Answer

It sounds like the stub is just a cut down version of the main model right?

Maybe "BareBonesObject" contains just enough to create an instance, and "FullObject" carries everything?

Nothing wrong with that kind of scenario.

Using RhinoMocks to save you from writing "BareBonesObject" seems like a code smell and overkill. Is it that much of a pain to write "BareBonesObject"?

Related Topic