Data - Data Models
Introduction
Data Models are a way to represent business objects into an application.
A Data Model is composed of Data Types and relationships between them. Properties can be added to these models and they can be connected together in order to create relations:
Properties and Relations
Properties are the attributes that have the same lifecycle as the object: when the object is deleted, the property is deleted.
Relations are the attributes that have a different lifecycle as the object: when the object is deleted, the related object is not deleted. Moreover, it is possible to link more than one object within a single relation:
Best practices
Use Strong Typing when defining a Data Model. E.g. : A model which has a temperature property should have a property of type “Temperature” (≠Number). Temperature can then be used independently of the unit (celsius, fahrenheit, …).
Define then functions to get the value as a number: E.g Temperature as °F, Temperature as °C, ...
Exercise 7 – Notes data model
The goal of this exercise is to create the data model of the "Notes" app.
- Go to Project “Notes”.
- Open Folder “Data”.
- Create a new Data Model named “Notes Data Model”.
- Open the new Data Model.
- Create a Data Type named “Note”:
- Add String property “Summary”
- Add String property “Content”
- Create a Data Type named “Category”:
- Add String property “Name”
- Create a relation from Data Type “Note” to Data Type “Category” by dragging&dropping the "Category" model from the Marketplace to the "Note" Relations field. Name it ”Category”.