Exercise: Creating the Address Class
Now let’s enrich the contact application to include an address for each contact. As an exercise, create the application's Address class using the Studio New Caché Class Definition wizard:
-
The classname is Address.
-
It belongs to the ContactDB package.
-
Its ClassType is Serial—Note that this differs from Contact, which has ClassType Persistent.
-
In addition to extending %SerialObjectOpens in a new tab, it extends %PopulateOpens in a new tab, %XML.AdaptorOpens in a new tab, and %ZEN.DataModel.AdaptorOpens in a new tab.
Address should contain the following properties:
Property Name | Type |
---|---|
Street | %String |
City | %String |
State | %String |
Zip | %String |
After creating the class definition, click Build–>Compile to compile the class. Then complete the following steps:
-
Add a Home property of type ContactDB.Address to Contact. The property declaration looks like this
Property Home As ContactDB.Address;
-
Use the Terminal to delete all of the existing Contact instances. Use the following command:
USER>Do ##class(ContactDB.Contact).%KillExtent()
-
Use the Terminal to re-populate Contact with contacts that also have address data. Use the following command. Note that the population utility will automatically assign address data to the new contacts.
USER>Do ##class(ContactDB.Contact).Populate(10)