Skip to main content
Previous sectionNext section

Creating and Populating the Application Object Model

The application object model comprises a pair of classes: Contact and PhoneNumber, representing contacts and their phone numbers. Here is a diagram depicting this object model.


Use Atelier to create and compile SOAPTutorial.Contact and SOAPTutorial.PhoneNumber in the USER namespace.


Class SOAPTutorial.Contact Extends (%Persistent, %Populate, %XML.Adaptor)

    /// Represents a contact's name
    Property Name As %String(POPSPEC = "Name()", TRUNCATE = 1) [ Required ];

    Relationship PhoneNumbers As SOAPTutorial.PhoneNumber [ Cardinality = children, Inverse = Contact ];

   /// Describes the nature of the contact: Personal or Business
   Property ContactType As %String(TRUNCATE = 1, VALUELIST = ",Business,Personal", XMLPROJECTION = "ELEMENT");


Copy code to clipboard


Class SOAPTutorial.PhoneNumber Extends (%Persistent, %Populate, %XML.Adaptor) 

Relationship Contact As SOAPTutorial.Contact [ Cardinality = parent, Inverse = PhoneNumbers ];

/// Represents a phone number
Property Number As %String(POPSPEC = "USPhone()", TRUNCATE = 1);

/// Represents the type of phone number, e.g., work, home, mobile, fax, etc.
Property PhoneNumberType As %String(TRUNCATE = 1, VALUELIST = ",Business,Home,Mobile,Fax");

Copy code to clipboard

Once you have successfully compiled Contact and PhoneNumber you can populate them with data. Run the population utility from Terminal. Complete the following steps for Contact and then for PhoneNumber:

  1. Launch Terminal from the InterSystems IRIS launcher.

  2. At the Terminal prompt, use the $namespace variable to switch to the namespace containing your classes. For example, if the Terminal opens in SAMPLES and your classes are in USER, do the following:

    SAMPLES>set $namespace="USER"
    Copy code to clipboard
  3. Next, use the populate utility to create a few instances of Contact. Here is the command to create five instances:

    USER>do ##class(SOAPTutorial.Contact).Populate(5)
    Copy code to clipboard

    Note that the command requires that your provide the package name along with the classname using the PackageName.ClassName syntax. Populate's first argument, 5 in this case, specifies the number of instances to create. Passing a 1 in Populate's second argument causes the utility to provide feedback as it creates each instance.

If at some point in the future you want to remove all instances of Contact or PhoneNumber, use %KillExtent. The following command removes all instances of SOAPTutorial.Contact from TUTORIALS:

USER>do ##class(SOAPTutorial.Contact).%KillExtent()
Copy code to clipboard

You cannot create instances of PhoneNumber before you create instances of Contact. This is because the two classes form a parent-child relationship with Contact as the parent. Each PhoneNumber instance must belong to a Contact instance.