Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Provide constructors with shorter parameter list for classes that implement interfaces Cloudlet, Vm, Host, Datacenter and DatacenterCharacteristics #30
Several basic classes such as the CloudletSimple have very complex constructors with lots of parameters. The CloudletSimple class constructor, for instance, has 9 parameters. Constructors with a shorter parameter list have to be introduced for these classes in order to make them easier and less confusing to instantiate.
Detailed information about how the feature should work
New constructors have to be introduced for such classes and the other constructors would be marked as deprecated for future removal.
Values of required attributes should be defined by the developer using setter methods.
An example scenario where this feature should be used
The use of constructors with shorter parameter list and the setters to define the object attributes values will make the code to create such objects clearer. Examples will be simpler since a developer reading them will see each attribute being set individually. He/she can directly understand which value is being given for which attribute. With several parameters in the constructor, as the case of the CloudletSimple class, it is not direct to know what means each value being passed. Sometimes the developer has to resort to the constructor documentation or even its source code to know which value is being set to which parameter.
A brief explanation of why you think this feature is useful
As the number of constructor parameters increases, it makes more difficult to call the constructor. As new attributes are introduced, new constructors with more parameters tend to be included, worsening the problem. The usage of appropriated default values for attributes such as the number of PEs a Cloudlet requires to reduce the number of setters to be called when the developer wants to use some of these default values.
This feature aligns with clean code programming, that suggests methods should not have more than 3 parameters. Since that using these simpler constructors and deprecating the other ones avoids the introduction of new constructors with more parameters, it makes the code maintenance easier.
The class usage is simplified, since there is not pre-defined order to call the setters to define attribute values. It is also not required that all the attributes are explicitly set, once some of them may use the default value.