Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 1.2

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.