Re:Dependency Injection is a Virtue
by masklinn on Monday January 07, 2013 @07:38AM
(#5020681)
I would have gone with "sane defaults":
def publish!(time=Time.now)
self.update published_at: time
end
keeps the simple case simple (self.publish!) but allows injection if needed (custom publication time or testing stub).
My language of choice being Python, I tend to do that rather often for injecting "classes" which will have to be instantiated: the function or object constructors takes callables (since Python's instantiation is just calling) with defaults provided.
My language of choice being Python, I tend to do that rather often for injecting "classes" which will have to be instantiated: the function or object constructors takes callables (since Python's instantiation is just calling) with defaults provided.