I have a method that takes 2 parameters today to complete the computation. The prospects of these 2 parameters becoming 50 in the future is pretty good. Given this, what is good?
- Write
func(int a, int b)
today. When parameters go beyond 7, then transition to 2 or 3 below. - Write
func(RootOfObjectGraphWith50Fields a)
today(RootOfObjectGraphWith50Fields
is used in other parts of the code base). This way when more parameters are needed, the method signature need not change. But this increases coupling (the method needs to know more to complete its business). - Write
func(InterfaceWith50Fields a)
today (with only 2 fields) and haveRootOfObjectGraphWith50Fields
implementInterfaceWith50Fields
. This way the method signature does not have to change every time a new value is required to complete the computation. The method is not coupled to the entireRootOfObjectGraphWith50Fields
but only to those fields that it is interested in (expressed inInterfaceWith50Fields
).
Besides recommendations, I appreciate pointers to basic design principles behind the recommendations.
Aucun commentaire:
Enregistrer un commentaire