In Parham almost all properties (methods, attributes) can be marked extern.

An extern property is a property that a component uses but does not provide the property itself

Tree example

In this example, the binary tree data structure is developed.

A binary tree stores elements based on an ordering. Therefore it needs a method to know the order of its elements. For this purpose it introduces an extern method.

extern int Node.compare (Node);

The App component introduces an instance of Tree to store a set of Persons. Therefore, it should provide an implementation for Node.compare method.

As Node is mapped on Person, the Person class of App should have a compare method.

int Person.compare (Person p)

The example has three files.

  • Tree component
  • App component
  • I/O functions in C

Parts of the Tree and App components are are provided in the front panel. However, the complete source of the example can be downloaded from the link given in the above of the page.

Tree[Root, Node]


extern int Node.compare (Node);


Root -> Node root;

Node -> Node left, right;


Root ()

{

   root = null;

}

public void Root.insert (Node n)

{

   Node ptr;


   n.left = n.right = null;

   if (root == null)

   {

       root = n;

       return;

   }

   for (ptr = root; ; )

   {

       if (n.compare (ptr) <= 0)

       {

           if (ptr.left)

               ptr = ptr.left;

           else

           {

             ptr.left = n;

               return;

         }

       }

     else if (ptr.right)

        ptr = ptr.right;

     else

       {

           ptr.right = n;

         return;

       }

   }

}


Parts of Tree component

App


foreign int cstrcmp (char[] str1, char[] str2);

foreign void cprint (char[] msg1, char[] msg2);

foreign char[] cread ();


People[];

Person[];


Person

{

    char[] name;

}

Person (char[] _name)

{

    name = _name;

}

int Person.compare (Person p)

{

    return cstrcmp (name, p.name);

}


Tree[People, Person];


Parts of App component