Domanda

I need to create a trait for my class solely for dependency injection for my unit tests. I don't really foresee any other implementations of this trait -- just need to stub it for unit tests. Say my class is named "Foo"... in .NET I would have called my interface "IFoo." What convention do people use for this case?

È stato utile?

Soluzione

When there's only likely to ever be 1 implementation of a trait, it makes sense to use the "Impl" convention: trait = Foo and class = FooImpl. Though I've never really been a fan of this convention because it's kind of limiting to one implementation, it sounds like that's exactly what I need here.

When more classes implement an interface/trait, it's more likely that naming each implementation will flow more naturally.

Altri suggerimenti

The activator template for akka-spray uses a DIY injection pattern. They name one of its main interfaces Core and its implementation RunCore. It seems, they're suggesting to come up with a descriptive name for the implementation depending on its intended use, rather than just impl. Following through, you would name your mock TestCore.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top