Component Body

From Parham Language
Jump to: navigation, search

The body of a component defines the behavior of the members of its sets. Parham has four categories of declarations for this purpose. They are as the following.

  1. Explicit
  2. Association
  3. Inclusion
  4. Instantiation


Explicit declaration is used to assign fields, methods or constructor to the members of a set. The type of the fields should be primitive or internal set. For example, assume that a Counter component is defined. It has a set that contains the counter and operations to increase or decrease it.

Counter[This] {

       int value;
       This ()
           value = 0;
       void inc ()
       void dec ()
       int get ()
           return value;


In the above example, Counter component has an interface set: This. In the body of the component, the behavior of the This set is defined. It has an attribute (value), a constructor and three methods: inc, dec and get.


An association defines a link from a member of a set to a member of another or the same set. In fact, it adds a pointer to the source set which refers to the target set. This is an example of an association.
Root -> Node head;
It defines an association from Root set to Node set whose name is head.

As another example of association, consider the implementation of Queue component.

Queue[Root, Node] {

   Root -> Node head, tail;
   Node -> Node next, prev;
       Root ()
           head = tail = null;
       void enqueue (Node node)
  = head;
           node.prev = null;
           if (head)
               head.prev = node;
               tail = node;
           head = node;



When there is a common behavior between two sets of a component, it is desirable to factor it. This is called generalization. On the other hand, it is possible to specialize the members of a set. For example, a person is male or female. To define such generalizations/specializations, Parham defines inclusion.

Person = Male | Female;

Note that the union set (Person in the above example) should be an internal set.


Except the main component, other components should be instantiated in order to be used. When a component is instantiated, its interface sets should be mapped to the sets of the instantiating component.

For example, assume that the scheduler of an operating system, has a processes waiting for execution. It is defined as follows.

Scheduler[This, Process] {

   Queue[This, Process];


In the above example, Root set of Queue is mapped onto the This set of Scheduler and Node set of Queue is mapped onto the Process set of Scheduler. In this manner, the role of Root is assigned to the memers of This set and the role of Node is added to the members of Process set.

In the above example, the mapping did not assign any name to the added roles. However, it is possible to name them too. This is an example of this case.

Scheduler[This, Process] {

   Queue[This readyQueue, Process];


In this case, one of the role has named: readyQueue