Graphics Programs Reference
In-Depth Information
For the More Curious: Class Names
In simple applications like RandomPossessions , we only use a handful of classes. However,
as applications grow larger and more complex, the number of classes grows. At some point,
you will run into a situation where you have two classes that could easily be named the
same thing. This is bad news. If two classes have the same name, it is impossible for your
program to figure out which one it should use. This is known as a namespace collision .
Other languages solve this problem by declaring classes inside a namespace . You can think
of a namespace as a group, to which classes belong. To use a class in these languages, you
have to specify both the class name and the namespace.
Objective-C has no notion of namespaces. Instead, we prefix class names with two or three
letters to keep them distinct. For example, in this exercise, the class was named BNRItem
instead of Item .
Stylish Objective-C programmers always prefix their model and view classes. The prefix is
typically related to the name of the application you are developing or the library it belongs
to. For example, if I were writing an application named “MovieViewer,” I would prefix all
classes with MV . Classes that you will use across multiple projects typically bear a prefix
that is related to your name ( JC ), your company's name ( BNR ), or a portable library (a lib-
rary for dealing with maps might use MAP ).
Controller objects, on the other hand, are typically only used in a single application and do
not need a prefix. This isn't a rule - you can prefix your controller objects if you like, and
you definitely should if they will be used in other applications.
Notice that Apple's classes have prefixes, too. Apple's classes are organized into frame-
works (which we'll talk about in Chapter 4 ), and each framework has its own prefix. For
instance, the UILabel class belongs to the UIKit framework. The classes NSArray and
NSString belong to the Foundation framework. (The NS stands for NeXTSTEP, the plat-
form for which these classes were originally designed.)
Search WWH ::




Custom Search