Article Preview
Buy Now
COLUMN
Wrapper Classes
Issue: 1.2 (October/November 2002)
Author: Charles Yeomans
Article Description: No description available.
Article Length (in bytes): 4,679
Starting Page Number: 36
Article Number: 1117
Related Web Link(s):
http://www.quantum-meruit.com/RB/
Excerpt of article text...
The wrapper class is a standard trick of object-oriented programming. Apparently, it is so standard that I could not even find a definition of the term on the web. This may be because the notion of a wrapper class has become so general as to defy a precise definition. Nevertheless, its use is often suggested on the REALbasic mailing list to solve various problems, so it's worth a discussion.
Originally, a wrapper class was a class used to encapsulate, or wrap, a non-object thing so as to be able to treat it as an object. A first, obvious, application for RB coders is to wrap OS calls.
Declares can sometimes be tricky to get right. Once you've done so, it is frequently convenient to wrap them in a class for reuse, instead of cutting and pasting. For example, I wrote a wrapper class which reads a Macintosh application's 'SIZE' resource (project available at
http://www.quantum-meruit.com/RB/ ). The class hides the dirty work of reading and parsing the resource inside an object with a simple interface.Another use is to wrap some data, such as an integer, into an object. You might do this because the integer really represents an object which should have some capability, or because two objects need to hold a reference to the same integer value.
Yet another example of a wrapper class is REALbasic's generic data type, the Variant class, which can contain any object or datatype.
Over time, the term "wrapper class" has come to be used for any class whose purpose is to provide an interface to other objects. The book
Design Patterns distinguishes at least four distinct patterns (Decorator, Adapter, Composite, and Facade) which qualify as wrapper classes of a sort. A distinguishing feature of a wrapper is that its methods are frequently no more than a few lines which call a method of another object.
...End of Excerpt. Please purchase the magazine to read the full article.