Composition of objects vs functions: Should I use one method interfaces or
delegates?
C# is a multi paradigm language. With nesting interfaces and classes one
can get a composition of objects. This way a certain problem can be broken
down to a number of simple ones giving each component its own piece of the
puzzle to solve. The same trick can be done in a slightly different
manner, one can make a composition of functions each of which is
responsible of solving its own little task while all combined and
interconnected they give the answer to the main problem.
Following SOLID principles I found myself in a situation where 95% of my
interfaces carry just one method named do-something and the name of the
interface is something-doer. The class that implements such interfaces is
DI'ed with the a few components required to fulfill whatever that method
is supposed to do. Such approach is basically making a closure over a
function by hands. If so, why wouldn't I just go with delegates that do it
naturally and for free (no typing necessary)? If I go all the way
converting single method interfaces to delegates I will eliminate 95% of
them from my code making it look like written in functional language. But
this seems like a right thing to do unless there is some bold reason to
stick with interfaces. Is there?
No comments:
Post a Comment