Foundation objects, Representing objects as strings, Mutable and immutable objects – Apple WebObjects 3.5 User Manual

Page 189

Advertising
background image

189

As you learned in the previous chapter, when you write an application in
WebScript, all values are objects, even simple values such as numbers or
strings. The objects that represent strings, numbers, arrays, dictionaries,
and other basic constructs are defined by classes in the Foundation
framework. You use classes from the Foundation framework in virtually all
WebScript applications.

This chapter gives you an overview of the Foundation framework classes
most commonly used in WebScript. More detailed descriptions are
provided by the class specifications in the Foundation Framework Reference.
However, not all methods in these class specifications are available in
WebScript. For example, some classes define methods that take structures
as arguments or return structures, but because structures are not supported
in WebScript, you cannot use these methods. For more information, see
“WebScript for Objective-C Developers” (page 183) in the previous
chapter.

Foundation Objects

This section provides an overview of some of the topics, techniques, and
conventions you use when programming with Foundation objects.

Representing Objects as Strings

You can obtain a human-readable string representation of any object by
sending it a

description

message. This method is particularly useful for

debugging. In some cases, the string returned from

description

contains only

the class name of the object that received the message (the receiver). Most
objects, however, provide more information. For class-specific details, see
the

description

method descriptions later in this chapter.

Mutable and Immutable Objects

Some objects are immutable; that is, once they are created, they can’t be
modified. Other objects are mutable. They can be modified at any time.
When you create an object, you can often choose to create it as either
immutable or mutable. Three kinds of objects discussed in this chapter—
strings, arrays, and dictionaries—have both immutable and mutable
versions.

It’s best to use immutable objects whenever possible. Use a mutable object
only if you need to modify its contents after you create it.

Advertising