Humax Raiya Programming

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Introduction to Humax Raiya Programming[edit]

Humax web framework introduces "Raiya" in version 0.3 (means water which is the most qualified resource for mix up with any other resource) which enables programmer to define generic functionalities on it, later it can be plugged into any Humax compatible class. When this happen, all the plugged raiya's methods are immediately available as methods in the class as well. In this way, you can extend a class without affecting its core functionality.

There are three ways you can build a raiya:

  • Native cohesive raiya. These types of raiyas are developed for a family of classes those are owned and understand by the raiya developer itself. In this case, the raiya developer knows the private members of the target base class (mostly base class) and uses these members directly in the raiya.
  • Native closed raiya. These types of raiyas are developed for providing extensibility to the classes from third party. They know their public methods and uses that methods in the raiya.
  • Self contained raiya. These types of raiyas are developed without targeting any classes. These raiyas are implemented for a generic functionality. Later any required classes can plug these raiyas into them by RaiyaFieldMapFacet.

Necessary for Raiya[edit]

Assume that there is a necessary to provide a "city" based filter to fetch the customers only from the given city. You add new public method in the CustomerCollection for this functionality. Consumer of this class should aware and use this method. However, in real case, adding more and more generic or non-generic functionality to the classes makes the system complex and sometime results repeated implementation for example the "filter" functionality in CustomerCollection. The object oriented approach does not help this scenario none other than derive a new class from the current one or implement it on the class itself. If the class we need to add functionality is actually developed by some third party, self implementation does not help. Since, multiple inheritance is strictly not recommended in the programming world, Humax lets you achieve this using "Raiya".

$raiya() allows to define raiya. See the following code.

$raiya("HxTest.CityFilterRaiya", { filter : function(cityName) { var filteredCollection = new HxTest.CustomerCollection(); for(var i = 0; i < this._customers.length; i++) { if(this._customers[i].getCity() == cityName) filteredCollection.add(this._customers[i]); } return filteredCollection; } });

The first argument should be raiya name and second argument should be the methods declaration. Both these are mandatory to define a raiya and no other things required. Here, CityFilterRaiya is a native cohesive raiya since it directly handles the CustomerCollection's private member this._customers. Applying Raiya

Humax compatible classes now have a method include for plug-in a raiya on it. The following code explains this.


Now we can use the filter function in the instances of CustomerCollection.


The above code returns CustomerCollection of "Chennai" based customers.

External links[edit]