Special

Clearance Sale!

We've been publishing for over five years now and it's time to clear out our inventory of back issues, so we're slashing prices!

RBD Magazines

Check out this amazing clearance sale of all our past issues. Missing some issues? This is a great time to complete your RBD collection. Save up to 40% off the regular price of our printed back issue packages. These prices are only good until the end of the year May 2008 and supplies are limited, so place your order today.

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