Currently, there is some logic needed for creating a model instance that relies on the developer to remember to implement it when creating that instance. This is not a good practice. We want to encapsulate this logic within the model so we don't need to use them outside of the model, thus avoiding repeating code. The image below is an example of how we can instantiate a model:
In this example, we can see that we need to set the id using the utility generateID() function. We'll need to do that everytime we create an instance of a model, which is not good. Likewise, for the OrderModel we need to always implement codeNumber initialization outside of the model.
This PR intends to change this design to a more reliable one in which the logic for creating these fields will be encapsulated within the model.
Only the necessary data (the one can't be created within the model) will be required to be entered to create an instance.
This is what we achieved with this PR:
Resolves #25
Currently, there is some logic needed for creating a model instance that relies on the developer to remember to implement it when creating that instance. This is not a good practice. We want to encapsulate this logic within the model so we don't need to use them outside of the model, thus avoiding repeating code. The image below is an example of how we can instantiate a model: In this example, we can see that we need to set the id using the utility
generateID()
function. We'll need to do that everytime we create an instance of a model, which is not good. Likewise, for theOrderModel
we need to always implementcodeNumber
initialization outside of the model. This PR intends to change this design to a more reliable one in which the logic for creating these fields will be encapsulated within the model. Only the necessary data (the one can't be created within the model) will be required to be entered to create an instance. This is what we achieved with this PR: