Say I have a localised struct called MyStruct with the following body:
struct MyStruct {
myField1 string
myField2 string
myField3 string
...
myFieldN string
}
And a function which instantiates new MyStructs for external callers:
func NewMyStruct(myField1, myField2, myField3, ..., myFieldN string) MyStruct {
return MyStruct{
myField1: myField1,
myField2: myField2,
myField3: myField3,
...
myFieldN: myFieldN,
}
}
Question: How would I best deal with the scenario of there being just too many fields within the struct resulting in a NewMyStruct(... function with way too many parameters? Is there any best practice to mitigate this issue? As of now, I have several functions like this in my codebase:
func NewSuperStruct(myField1, myField2, myField3, myField4, myField5, myField6, myField7, myField8, myField9, myField10, myField11, myField12, myField13, myField14, myField15, myField16, myField17, myField18, myField19, myField20, myField21, myField22) ...
But it's not necessarily that the structs themselves are nonsensical in the sense that the properties/fields don't belong within, in my application they do make sense, the structs are just too large, that's all.