New Issues
Let’s learn about some of the new issues that will arise in our new application.
We'll cover the following
New issues in subtyping
Compared to the EnumerationApp, we have to deal with several new issues:
-
In the model code, we need to do the following:
- Add a constraint violation class
FrozenValueConstraintViolation
toerrorTypes.js
. - Code the enumeration type to be used as the range of the
category
attribute (BookCategoryEL
in our example). - Code the
checkCategory
function for thecategory
attribute. In our example, this attribute is optional because theBook
segmentation is incomplete. If the segmentation which the Class Hierarchy Merge pattern is applied to is complete, then thecategory
attribute is required. - Code the
check
functions for all segment properties so that they takecategory
as a second parameter. This is so we may be able to test if the segment property concerned applies to a given instance. - Refine the serialization function
toString()
by adding a category case distinction (switch
) statement to serialize only the segment properties that apply to a given category. - Implement the frozen value constraint for the
category
attribute inBook.update
by updating thecategory
of a book only if it hasn’t yet been defined. This means it can’t be updated anymore as soon as it has been defined.
- Add a constraint violation class
-
In the UI code, we need to do the following:
- Add a “Special Type” (or “Category”) column to the display table of the List All Books sections in
books.html
. A book without a special category will have an empty table cell. In contrast, their category will be shown in this cell, along with other segment-specific attribute values for all other books. This requires the correspondingswitch
statement inpl.v.books.retrieveAndListAll.setupUserInterface
in thebooks.js
“View Code” file. - Add a “Special Type” choice widget (typically, a selection list) and the corresponding form fields for all segment properties in the forms of the “Create Book” and “Update Book” sections in
books.html
. Segment property form fields are only displayed when a corresponding book category has been selected. The approach of rendering specific form fields only on certain conditions is sometimes called dynamic forms.
- Add a “Special Type” (or “Category”) column to the display table of the List All Books sections in
Get hands-on with 1400+ tech skills courses.