I observe the same pattern in a number of my classes but can't extract/abstract it due the tight coupling inside each particular implementation.
Having the class accepting an optional number of dependencies onto its constructor:
public Repository(IBuilder, IFormatter, ILoader, ISelector)
With the single method passing its arguments to the first dependency. Passing result to the second. And so on. Returning result of the last dependency:
public XElement Do(int i)
{
string q = _builder.Build(i);
string f = _formatter.Format(q);
XDocument d = _loader.Load(f);
XElement r = _selector.Select(d);
return r;
}
(names of the classes, methods and variables are random, just to illustrate the pattern)
Can it be refactored to decouple the flow from the types of dependencies, arguments and return values?
It also will simplify the (unit) testing because currently I make sure that a dependency N passes its result to a dependency N+1:
[TestMethod]
public void Do_Should_Pass_Result_Of_Build_To_Format()
D(i)
callsD(i+1)
. \$\endgroup\$Do_Should_Pass_Result_Of_Build_To_Format
: You clearly are testing the implementation details. \$\endgroup\$