Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide constructors with shorter parameter list for classes that implement interfaces Cloudlet, Vm, Host, Datacenter and DatacenterCharacteristics #30

Closed
manoelcampos opened this issue Oct 7, 2016 · 0 comments
Assignees

Comments

@manoelcampos
Copy link
Collaborator

manoelcampos commented Oct 7, 2016

IMPROVEMENT

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.
Appropriated default values should be provided for such attributes. For instance, the minimum number of PEs a Cloudlet must have is 1, thus this may be the default value. Attributes of specific interfaces such as UtilizationModel may be initialised with the NULL object from these interfaces.

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 no 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.

Related Issues

@manoelcampos manoelcampos changed the title Provide a default, no-args construtor for classes such as CloudletSimple, VmSimple and HostSimple Provide constructors with not too long parameter list for classes that implement interfaces Cloudlet, Vm, Host, Datacenter and DatacenterCharacteristics Nov 16, 2016
@manoelcampos manoelcampos self-assigned this Nov 16, 2016
@manoelcampos manoelcampos changed the title Provide constructors with not too long parameter list for classes that implement interfaces Cloudlet, Vm, Host, Datacenter and DatacenterCharacteristics Provide constructors with shorter parameter list for classes that implement interfaces Cloudlet, Vm, Host, Datacenter and DatacenterCharacteristics Nov 16, 2016
@manoelcampos manoelcampos added this to the CloudSim Plus 1.0 milestone Dec 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant