Android Question Coding style for b4x object's initialization parameters?

Hanz

Active Member
Hello,

May I know what are the recommendations of the elders of b4x for the maximum number of parameters of "initialize" of an object? In Java, some recommend that it should not be more than 5 or 6 parameters to initialize an object. They say, beyond that number, it is no longer convenient. I asked because recently I created a project and one of the object has 11 parameters to initialize and it seems crowded already. Am I still doing it right? I see some programmers here who do the same thing, but I don't know if they are doing it for demo only or for discussion.

Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
11 parameters sounds too much.

There are all kinds of ways to refactor it. One possible solution is to create a custom type and include all parameters in this type. This will also be more maintainable as you will be able to easily add more parameters in the future.

B4X:
Dim iv As DataRequiredForObject
iv.Parameter1 = value1
iv.Parameter2 = value2
iv.Parameter3 = value3
MyObject.Initialize(iv)
 
Upvote 0
Top