Model Code: Property Checks and Property Setters
Let’s learn how to code the property checks and property setters for the model.
We'll cover the following
Code the property checks
We code the property check functions in the form of class-level (“static”) methods. In JavaScript, this means we define them as method slots of the constructor, as in Book.checkIsbn
. Recall that a constructor is a JavaScript object, since in JS, functions are objects, and as an object, it can have slots.
Take care that all constraints of a property as specified in the class model are properly coded in its check function. This concerns, in particular, the mandatory value and uniqueness constraints implied by the standard identifier declaration (with {id}), as well as the mandatory value constraints for all properties with multiplicity 1, which is the default when no multiplicity is shown. If any constraint is violated, an error object instantiating one of the error classes listed in the lib folder and defined in the file errorTypes.js
is returned.
For instance, for the checkIsbn
operation, we obtain the following code:
Get hands-on with 1400+ tech skills courses.