Chapter 2. Implementing Unidirectional Functional Associations with Plain JS

Table of Contents
1. New JavaScript Elements
1.1. Block-Scope Variable Declarations with let and const
1.2. Arrow Functions
1.3. For-Of Loops over Iterable Objects
1.4. Template Literals
1.5. The Spread Operator
1.6. Destructuring Assignments
2. Implementing Single-Valued Reference Properties
3. Make a JS Class Model
4. New Issues
5. Code the Model
5.1. Summary
5.2. Code each model class as an ES2015 class
5.3. Code the property checks
5.4. Code the property setters
5.5. Choose and implement a deletion policy
5.6. Serialization and Object-to-Storage Mapping
6. Code the View and Controller
6.1. Initialize the app
6.2. Showing associated objects in Retrieve/List All
6.3. Selecting associated objects in the Create and Update use cases
7. Quiz Questions
7.1. Question 1: JS class model

A unidirectional functional association is either one-to-one or many-to-one. In both cases such an association is represented, or implemented, with the help of a single-valued reference property.

In this chapter, we show

  1. how to derive a plain JS class model from an OO class model with single-valued reference properties representing unidirectional functional associations,

  2. how to code the JS class model in the form of plain JavaScript model classes,

  3. how to write the view and controller code based on the model code.

Before we show how to derive a plain JS class model and code it in JavaScript, we first introduce a few new elements of the JavaScript language, which we are going to use throughout the JavaScript code discussed in this book.