Background
Maps are not new concept in software development actually. They are table wrappers to achieve general behavior. However for lame dude(s) like me, these definition words have not been enough.
Problem
The term allotted to Maps, "Map" itself is a bit confusing. But an example can really help understanding. And Maps are used everywhere, but in comparison to tables and classes ( see these building blocks are essential for any kind of most basic development), use of maps are quite rare.
Example
I have been browsing PurchTableHistory table. A method came into my consideration where I see the use of Map.
The method, PurchTableHistory[T] >> initFromPurchTable() declares several maps based on localized buffers. Look at the following code
// Code examplePurchTableMap purchTableMap;purchTableMap.data(_purchTable.data());this.data(purchTableMap.data());
First, the row from PurchTable is copied to the map variable, 'purchTableMap', and then, the history buffer gets the same row but form map, and not from the original source, purchTable buffer
WHY ? Their must be a genuine need ? Why don't we copy from the original PurchTable buffer ? Becuase we cannot :) becuase of schema change. See if most of the fields are same but not with exact field names, types and filed list count, we cannot copy a row from one table to another using xRecord[C].data() simply because of schema mismatch.
Here is where map can work, since the different name same type and purpose fields are MAPPED in the MAP :). Fields with different names from different tables are mapped to consistent names in map, so that you can use them to map one row ( from one table buffer) to another table.
One more thing, when using maps, field count doesn't matter since the map will only care and execute on the schema defined in the map. It simply would not care for schema defined in the mapped tables, it would only care for the schema defined in the MAP
No comments:
Post a Comment