In this chapter, we first explain the general approach to constructor-based subtyping in JavaScript before presenting two case studies based on fragments of the information model of our running example, the Public Library app, shown above.
In the first case study, we consider the single-level class hierarchy with root Book
shown in Figure 12.1, which is an incomplete disjoint rigid segmentation. We use the Class Hierarchy Merge design pattern for re-factoring this simple class hierarchy to a single class that can be mapped to a persistent database table.
In the second case study, we consider the multi-level class hierarchy consisting of the Person
roles Employee
, Manager
and Author
, shown in Figure 12.8. The segmentation of Person
into Employee
and Author
does not have any constraints, which means that it is incomplete, overlapping (non-disjoint) and non-rigid.
We use the Class Hierarchy Merge design pattern for re-factoring the simple Manager
-is-Employee
sub-hierarchy, and the Joined Tables Inheritance approach for mapping the Employee
-and-Author
-is-a-Person
class hierarchy to a set of three database tables that are related with each other via foreign key dependencies.
In both case studies we show
how to derive a JS class model, and a corresponding entity table model, from the information design model,
how to code the JS class model in the form of JS model classes,
how to write the view and controller code based on the model code.