Special

Special Print Closeout!

We're clearing out the remainder of our print issues at fire sale prices -- as much as 75% off! Quantities are extremely limited and only available while supplies last. Hurry to take advantage of this one-time offer.

RBD Magazines

Once these printed back issues are gone, they are gone!

Article Preview


Buy Now

Print:
PDF:

Object-Oriented Thinking

Reconstituting Objects

Refactoring to Patterns

Issue: 5.1 (September/October 2006)
Author: Charles Yeomans
Article Description: No description available.
Article Length (in bytes): 5,783
Starting Page Number: 39
RBD Number: 5116
Resource File(s): None
Related Web Link(s):

http://www.declareSub.com/

Known Limitations: None

Excerpt of article text...

Here is our problem: we have saved persistent objects of various classes on disk as XML data. How do we read the objects back into memory?

Reading the XML and crunching it using the XML capability in REALbasic is simple enough. The real problem is how to create the persistent objects. The New operator requires that you specify a class at compile-time; that is, in code. But we only know the class of a persistent object at runtime, when we read it from the XML.

Now, classes, as opposed to instances of classes, cannot be created at runtime. Thus all possible classes are known. So the basic idea is to define a mapping from class names as Strings to calls to New. Starting from this, we proceed with a very simple implementation, and refactor it to improve encapsulation and isolate the the code that may need to be changed.

Let's begin with the method we know we need. We make it a shared method of Persistent, the parent class of all of our persistent objects, that takes a string representing the class name and returns an object of type Persistent. The simplest implementation is to write a Select Case statement.

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.


 


|

 


Weblog Commenting and Trackback by HaloScan.com