Code Summary
Let’s take a look at a summary of the steps we’ll use to code our application.
We'll cover the following
Step-by-step
You can code each class of the JavaScript class model as an ES2015 class with implicit getters and setters. Alternatively, you can use an ES5 constructor function with explicit setters:
- Code the property checks in the form of class-level static methods. Make sure that all constraints of a property, as specified in the JavaScript class model, are properly coded in the property checks.
- For each single-valued property, define the specified getter and setter:
- In each setter, the corresponding property check is invoked and the property is only set or unset if the check doesn’t detect any constraint violation.
- If the concerned property is the inverse of a derived reference property, make sure that the setter also either assigns or unsets (adds or removes) the corresponding inverse reference to or from the collection value of the inverse property.
- For each multivalued property, code its
add
andremove
operations, as well as the specifiedget
orset
operations:- Code the add and remove operations as instance-level methods that invoke the corresponding property checks.
- Code the setter so it invokes the
add
operation for each item of the collection to be assigned. - If the concerned property is the inverse of a derived reference property, make sure that the add or remove methods also assign or unset the corresponding inverse reference to or from the collection value of the inverse property.
- Write the code of the serialization function
toString()
and the object-to-storage conversion functiontoRecord()
. In the object-to-storage conversion of apublisher
orauthor
object with toRecord(), the derived propertiespublishedBooks
andauthoredBooks
aren’t included, since their information is redundant. - Take care of deletion dependencies in the
destroy
method. When an object with one or more references as the value of a leader reference property is destroyed, the derived inverse references first need to be unset.
These steps are discussed in more detail in the following sections.
Get hands-on with 1400+ tech skills courses.