Let's get a quick summary of the contents of this chapter.

We'll cover the following

Key takeaways

  1. Constraints are logical conditions on the data of an application. The simplest and most important types of constraints are property constraints and object-level constraints.

  2. Constraints should be defined in the model classes of an MVC application since they are part of their business semantics.

  3. Constraints should be checked in various places of an MVC application—in the UI/view code, in model classes, and possibly in the database.

  4. Software applications that include CRUD data management need to perform two kinds of bi-directional object-to-string type conversions:

    • Between the model and the UI, converting model object property values to UI widget values, as well as the other way around, converting input widget values to property values. Typically, widgets are form fields that have string values.

    • Between the model and the datastore, converting model objects to storage data sets (called serialization), as well as the other way around, converting storage data sets to model objects (called deserialization). This involves converting property values to storage data values and the other way around, converting storage data values to property values. Typically, datastores are either JavaScript’s localStorage or IndexedDB or SQL databases, and objects have to be mapped to some form of table rows. In the case of an SQL database, this is called “Object-Relational Mapping” (ORM).

  5. Don’t perform any string-to-property-value conversion in the UI code. That’s the business of the model code.

  6. To observe how an application works, it is essential to log all critical application events, such as data retrieval or save and delete events somewhere, like in the JavaScript console.

  7. Responsive validation means that the user, while typing, gets immediate validation feedback on each input (keystroke), as well as when requesting to save the new data.

Get hands-on with 1200+ tech skills courses.