Wrapping What You Dont Like

The practice of putting wrappers around paradigms, API's, etc. that we don't like to deal with directly.

Whether this is a good thing or bad is subject to debate. While few dispute wrapping lower-level operations, sometimes high-level API's or paradigms are also wrapped to give us the view or paradigm we want to see.

Example of OO wrapping SQL:

method getAllSmallPinkScarves() {
sql = "select * from products where product='scarf' and color='pink'
and size='small'";
return(qr = new database.query(sql))
}

(See NoStrings for more on this practice.)

Example of procedural wrapping OO to privide a shorter print call:

function print(myString) {
system.io.output.writer.print(myString);
}

How about wrapping procedural, with functional to escape low level loops

function forEach(aList, aFunction){
for(var i=0;i aFunction(aList[i]);
}

usage..

forEach(aList,function(each){
print(each.toString());
});

Wrapping OO with functional

function when(anObject, anEvent, aCallback){
if(anObject.attachEvent)anObject.attachEvent("on"+anEvent, aCallback);
else anObject.addEventListener(anEvent, aCallback, true);
}

allows more english like usage....

when(window,"load",function(anEvent){
//make all elements yellow
forEach(document.forms[0].items,function(each){
each.style.backgroundColor="yellow";
});
});

See also: FuzzyDistinctionBetweenInterfaceAndImplementation


CategoryAbstraction