banner banner  

Employing a very simple Service Oriented Architecture for 
Loosely Couple the Components in an Application

The webpage outlines a pattern for employing “Service Oriented Architecture”, to loosely couple the components within a RIA (Rich Internet Application). This coupling allows the ‘loosely coupled’ components to collaborate or communicate with each other.
FIG-1: A trivial implementation of directory of services 

Please assume, an online GUI application (e.g. webpage/RIA) contains many GUI components (or mashups) and they need to communicate or exchange data with each other. To accomplish this: each component (or each mashup) may be designed to register its service with a global “RegistrationObject” by using a predefined service name (Please see Fig#1 and #2). Then any other component in the RIA or webpage, which needs the service could lookup and access the service through the global “RegistrationObject” by using the predefined service name. Complete example below:

In such typical application (Fig#1): (a) each ‘loosely coupled’ component may offer one or more services for other components, and/or (b) each ‘loosely coupled’ component may consume one or more services of other components. Few components may neither provide nor consume services. Such components may be considered ‘loosely coupled’ components, having zero real dependency or coupling with other components.

FIG-2: How SRO facilitates communication between any two components

The above FIG-2 shows, how a global registration object (e.g. A Directory) may be used to facilitate communication between any two components (where one is service provider component and the another is service consumer component).

Lets see how this can be implemented in the RIA (e.g. webpage). A sample implementation of class definition for ‘Registration Object’ is given in Listing#1 (Please review complete but simple implementation below - just 15 line of actual code).

Listing-1: Simple implementation of Service Registration Class

  1. function RegistrationClass () { // BEGIN: Class Definition
  2.  
  3. // An array to save References to Service-functions or Objects
  4. var services_func = new Array();
  5. // An array to save Respective Names to lookup the services
  6. var services_name = new Array();
  7.  
  8.    // This function registers or Adds a service and its name.
  9.    // This method just appends them to respective arrays:
  10.    this.AddService = function(name_string, func_reference) {
  11.        // Add the Service Name to the Array at next Index
  12.        services_name[services_name.length]= name_string;
  13.  
  14.        // Add the Service-Function or Object for the Name
  15.        services_func[services_func.length] = func_reference;
  16.    }
  17.  
  18.   // This function searches for name of service "ser_name"
  19.   // If found, returns the reference to the service function
  20.   this.FindService = function (name_string) {
  21.      var indx;
  22.      for(indx = 0; indx < services_name.length; indx++)
  23.          if(name_string == services_name[indx])//If name is found
  24.              return(services_func[indx]); // Returns reference
  25.      return(null);
  26.   }
  27. } // End Of Class definition

Brief Description of above implementation of the 'Registration Class'

1.

This class implementation uses two arrays 'service_func' and 'service_name' to store the reference of the service-functions and the service-names respectively.

2.

Service-provider components use 'AddService' method to register their services. This method appends service-function and service-name to respective arrays (at same index-location).

3.

Service-consumer components use 'FindService' method to lookup each service. This method looks up 'service_name' array for the name-string. If the name is found, it returns reference of the service-function stored at corresponding index-location (e.g. indx) in 'service_func' array.

The RIA (e.g. Ajax/HTML-page, SVG, XAML/SilverLight or Flex/ActionScript) instantiates a global registration-object using the registration class as shown below:
RegistrationClass RegistrationObject = new RegistrationClass();
Here, Chief Designer/Architect can make a variable (e.g. ‘RegistrationObject’) a Reserved Global variable for the application. Then the developer of each service-provider component implements the code, so that the component register its services with the global registration object (by using a predetermined service name). For example, the component's code-block may include the following one line to register a service function.
RegistrationObject.AddService("Name_Of_Service",ReferenceTo_ServiceMethod);
For Example:
RegistrationObject.AddService ("Shopping Cart1", AddItemToInvioce);
If the name of the service is know (i.e. predefined by the application architect at the time of initial design), the developer of any component could design the component to get the reference of the service function (or object) by including the following call (in the code-block for the component to request the service):
Var func_reference=RegistrationObject.FindService("Name_Of_Service");

For Example:
 
1.  Lookup and Getting reference to the service method from the Registration Object: 
    var add_to_shopping_cart=RegistrationObject.FindService("Shopping Cart1");
  2.  Then calling the service method by passing proper data/parameters:

   add_to_shopping_cart(Inferface_version, item_xml_data, call_back);

The above SoA pattern may be used in a RIA to create communication code between any two 'loosely coupled' components, such as Mashups (or between patent pending 'Interchangeable Components', which are presented below & in this website).
   
 

Copy Right © 2013 SPPS Systems Pvt.Ltd. All Rights Reserved.
This Website presents patented and patent-pending Inventions and Discoveries