My question comes from this other question.
The first time I read the question, I understood (maybe worngly) that the OP was asking for a different way to initialize the object in such a way that it would allow him to extend and make easier the maintenance. Hence my answer.
However, some comments seem to agree with passing an array as a single argument would be even easier.
We usually don't turn a function with # named parameters into a function with a single array of # positions.
public Message(String id, String a, String b){...}
public Message(String[] arguments){...}
public Message(String... arguments){...}
Turning # named parameters (all the same type) into a array is something I have done back in my early days as coder. Back then, I realised how brittle they were. For example, these structures are very sensible to changes. The order of the elements within the array and the length of the array matters, because we map attributes, fields or variables to positions within the array.
The following question agree with me. The only apparent difference is that the former question, the function is a constructor and in the last one is a method.
So looking at both questions linked here, I see how on one side we are suggesting to use arrays the way I commented and on the other side, we are discouraging from doing the very same practice.
My question boils down to, from the OOP point of view, Are arrays (as data structures) suitable for constructors but unsuitable methods?
If yes. Why? Do we apply different "rules" to define constructor's and method's signatures? Ultimately, both are functions.
If not. When is appropriated to use one or another?
To me, both cases lacks on maintainability, readability and scalability.
params
keyword so that a variable number of arguments can be specified. It's hard to imagine how they would incorporate that into the language if it weren't useful. You haven't really explained why you think such practices are brittle.Params
class?