what pattern to use for multi-argument method?
Posted
by Omid S
on Stack Overflow
See other posts from Stack Overflow
or by Omid S
Published on 2010-05-14T00:32:33Z
Indexed on
2010/05/14
0:44 UTC
Read the original article
Hit count: 324
I have a method with the following signature: foo (Sample sample, Aliquot aliquot)
"foo" needs to alter a Sample object, either the first argument or from the second argument it can extract its Sample. For example:
foo (Sample sample, Aliquot aliquot) {
Sample out = null;
if (sample != null)
out = sample
else
out = aliquot.getSample()
return out;
}
But that is so un-elegant, other than reading the API a developer does not know the reference of the first argument overrides the Sample of the second argument.
Now, I could change "foo" to foo (SomeMagicalObject bar) where SomeMagicalObject is a tuple for Sample and Aliquot and holds some logic ... etc.
But I am wondering, are there some patterns for this question?
© Stack Overflow or respective owner