Collaboration is the interaction of some objects to accomplish a task. Evey object involved in a collaboration has a role.

Component and Class

In Parham, a component is the implementation of a collaboration. Moreover, classes are defined within components and define the role of the objects involved in the collaboration.

In Parham a component has two types of objects: internal and interface. An internal object is only accessible inside the component. Therefore, it behavior is completely defined by the component. Such objects are defined by internal classes.

An interface object is an object which is common between this component and some other components. It means that every component that has access to this object can define its own role for it. Therefore, the behavior of the object is the union of the roles defined by various components for it. Interface objects are defined by interface classes.

Component Instantiation

When a component needs the service of a component it has to declare an instance of that component. In fact except the main component that defines the application, all other components should be instantiated in order to be used.

When a component is instantiated its interface classes are mapped onto the classes of the instantiating component.

This example demonstrates the declarations of components, classes and component instances.

It is made from three files.

  • A Parham file defining Sample component
  • Another Parham file defining App component (the main component of the program)
  • A C file containing I/O functions
Sample component file

The definition of a component begins with its name and its interface classes.

Sample[SampleClass]

Then there are a set of declarations defining internal sets and  the attributes of the component.

It begins with the declaration of a foreign function. Recall that foreign functions are implemented in C language.

Then, Sample component defines the properties of SampleClass. It defines a field (count), a constructor and two methods for it.

App component

App component is the main component of the application. Therefore, it does not have any interface class. However, it has an internal class named Class.

After declaring the internal class, it has declared an instance of Sample.

Sample[Class];

By this declaration, Class inherits the methods and attributes of SampleClass of Sample component.

Finally, the component has the main function. In the main function it has declared object c whose type is Class.

The rest of the function makes an object of Class type and calls various methods on it.

I/O functions

Finally, the C file has the I/O functions which are called from Parham files.

Remember that they are marked by foreign modifier in Parham files.

Sample[SampleClass]


foreign void cprint (int count);


SampleClass

{

    int count;

}


SampleClass ()

{

    count = 0;

}

void SampleClass.inc ()

{

    ++count;

}

void SampleClass.print ()

{

    cprint (count);

}


Sample component

App


Class[];


Sample[Class];


foreign int main ()

{

    Class c;


    c = new Class ();

    c.print ();

    c.inc ();

    c.print ();

}


App component

#include <stdio.h>


void cprint (int count)

{

    printf (“value of count is %dn”, count);

}


I/O functions in C