Article Preview
Buy Now
COLUMN
Don't Use Strings
Use Classes That Express Your Design
Issue: 5.6 (September/October 2007)
Author: Charles Yeomans
Author Bio: Charles is the author of "I Declare: Calling External Functions in REALbasic", available online at
Article Description: No description available.
Article Length (in bytes): 6,107
Starting Page Number: 41
Article Number: 5615
Related Web Link(s):
http://www.declareSub.com/
Excerpt of article text...
If you have properties or variables in your code like TelephoneNumber as String, replace them with TelephoneNumber objects. You can get the compiler to do more work for you, and probably simplify your code.
It is, of course, quite convenient to add String properties to a class to represent telephone numbers, zip codes, or any other sort of data that you need in the course of writing an application. But when you assign to a String variable, how do you know that it's a telephone number? Why, you don't, unless you validate the data to determine whether it has the correct form. Even then, all you know is that the data is syntactically valid.
String, Integer, and other such datatypes are often referred to as "primitive" datatypes. You should think of them as building blocks for types that express the intent of your design. In REALbasic, one can define new types using classes, interfaces, or structures. For something like a telephone number, a class is the first choice.
...End of Excerpt. Please purchase the magazine to read the full article.