declare functionName(concreteArg1, concreteArg2, ...)or
declare functionName(containerArg)Here,
containerArg
is an argument of our type with methods returning concreteArg1
, concreteArg2
etc.I usually preferred the former way as it allowed more concise implementation body and also the method signature speaks for itself. And also we don't introduce a new type. And the calling code is shorter.
There's a substantial difference in favor of the latter though: if later you decide you need to pass some additional parameters (or you don't need some), you can easily do that if you are passing an instance of your own type, but you are screwed if everything is specified in the API: you cannot but break API (or add another almost duplicate method), and even if you are the only user of the API you need to change calls and implementations etc. in every single place.
Such a simple thought and has never crossed my mind until I stumbled upon it.
No comments:
Post a Comment