Overview

Two key factors in OOP (Object Oriented Programming) are:

  • Loose Coupling - making objects as discrete as possible so they can function on their own as well as functioning as resources for other objects.
  • Tight Cohesion - consistency within the object so that all members work together strictly for the purpose of the object. In other words, if you have an object that manipulates data rows, it should not have any members that work with presentation of the rows.

Another concept that helps programmers maintain consistency is to follow a defined Design Pattern. There are dozens (maybe hundreds) of defined Design Patterns. Design Patterns can be mixed and matched to form a custom design pattern. Really though, any 'pattern' that you use on a consistent basis can be considered a Design Pattern.

For reports, I use a pattern I call Data-Presentation-Control. We've already discussed Presentation. In this article I will discuss Data.

By using a Data object to work with data you extract from ARIS objects, you will have an easy-to-use and consistent way to package data for use in any presentation format including Excel, Word, HTML, XML, etc.

The MY_DATA class

For the MY_DATA class, I used Microsoft's .NET Data objects as a guide. I used the following members from the .NET Data library:

  • DataSet - a collection of DataTables
  • DataTable - a collection of rows and columns
  • DataRow - a collection of cells (data items based on a particular column)
  • DataRowCollection - a collection of DataRows
  • DataColumn - a single column in the table
  • DataColumnCollection - a collection of columns

Each of these members in turn will have their own members such as 'name' and 'type'.

Below (and attached) is the class

In the next article, I will bring this class and MY_EXCEL_REPORT class together in a report so you can see how they function.

Enjoy!

Rick Beddoe

Cargill Aris Technical Analyst

Minneapolis, MN, USA

 

//**********************************
// Javascript Library for ARIS
// Author : Rick Beddoe
// Date : 11/2011
//**********************************

function MY_DATA() {
    
    //public objects
    this.DataSet = function(){
        this.DataTables = [];
    }    
    
    this.DataTable = function(oTableName) {
        this.Rows = [];
        this.Columns = [];
        this.TableName = oTableName;
        
    }
    
    this.DataRow = function(){
        this.Columns = [];
        //row type: "header", "data"
        this.Type = "";
        //key/value pair
        this.Item = function(_column){
            return columnCheck(this.Columns, _column);
        }
        //collection of fields in the row
        this.ItemArray = [];
        
    }
    
    this.AddRow = function(oData, oTable){
       var  oDataRow = new this.DataRow;
       newRow(oData, oTable, oDataRow);       
       oTable.Rows.push(oDataRow);       
    };
        
    this.DatarowCollection = [];
    this.DataColumn = {};        
    this.DataColumnCollection = [];
    this.DataSortASC = function(a,b){
            return a.index-b.index;
       };       
    this.DataSortDESC = function(a,b){
            return b.index-a.index;
       };
    
    
    
    
    
    //private objects    
    function columnCheck(_columns, _column){
        
        var oColumnMatch = JSLINQ(_columns)
                           .Where(function(col) {return col.key == _column;})                    
                           .Select(function(col) {return col.key;}).ToArray();
        
        if(oColumnMatch.length == 0)
        {
            return null;
        }
        else
        {
            return _column;
        }
        
    }
    
    
    
  //Row Handling Functions      
    function writeRow(oData, oTable, oRow){ 
              var oDataRow = newRow(oData, oTable, oRow);
              oTable.Rows.push(oDataRow);
    }             
   
    
    function newRow(oData, oTable, oDataRow){
         oDataRow.Columns = oTable.Columns;
         oDataRow.Type = "data";
         oDataRow.ItemArray = {};    
         
         for (oField in oData){
             oDataRow.ItemArray[oDataRow.Item(oData[oField].key)] = oData[oField].value;
         }
         return oDataRow;
    }
}

 or register to reply.

Notify Moderator