Model Code

Let’s learn how the model of the application is coded.

Code each class of the JS class model

For instance, the Publisher class from the JS class model is coded in the following way:

Press + to interact
class Publisher {
constructor({ name, address }) {
this.name = name;
this.address = address;
// derived inverse reference property (inverse of Book::publisher)
this._publishedBooks = {}; // initialize as an empty map
}
get name() {... }
static checkName(n) {... }
static checkNameAsId(n) {... }
static checkNameAsIdRef(n) {... }
set name(n) {... }
get address() {... }
static checkAddress(a) {... }
set address(a) {... }
toString() {... }
toRecord() {... }
}

We add the derived multivalued reference property publishedBooks, but we don’t assign it in the constructor function. This is because it’s a read-only property that’s assigned implicitly when its inverse leader reference property Book::publisher is assigned.

Code the set methods of single-valued properties

Any setter for a reference property that’s coupled to a derived inverse reference property also needs to assign, add, or remove inverse references to and from the corresponding collection value of the inverse reference property. An example of such a setter is ...