Introduction 2
In the last demo, you created a contact card type using only Composition. The type is composed of the information of the card and also other contacts. However, this approach doesn’t make much sense.
Your approach has two main issues:
- The contacts database in your app is the main array of contacts plus the contacts inside each contact’s
relatedContacts
. - By deleting one contact, you’ll also completely delete all the related contacts from your database.
A simpler way to approach this is to use Aggregation and list all the contacts in an array. Contacts can have a link to other existing entries to create the relationship instead of containing the relative contact.
This means that each contact is composed of three string values and an aggregation of other contacts to form the relativeContacts
.
You need to specify a way to link contacts to each other instead of having one contain another. This is similar to how you can open a file from different locations without duplicating the file itself using shortcuts (on Windows) or aliases (on macOS).