Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Code Naming Basics

An often overlooked aspect of the design of object-oriented software libraries is the naming of classes, methods, functions, constants, and the other elements of a programmatic interface. This section discusses several of the naming conventions common to most items of a Cocoa interface.

Contents:

General Principles
Prefixes
Typographic Conventions
Class and Protocol Names
Header Files


General Principles

Clarity

Consistency

See also “Method Arguments.”

No Self Reference

Prefixes

Prefixes are an important part of names in programmatic interfaces. They differentiate functional areas of software. Usually this software comes packaged in a framework or (as is the case of Foundation and Application Kit) in closely related frameworks. Prefixes protect against collisions between symbols defined by third-party developers and those defined by Apple (as well as between symbols in Apple’s own frameworks).

Typographic Conventions

Follow a few simple typographical conventions when naming API elements:

Class and Protocol Names

The name of a class should contain a noun that clearly indicates what the class (or objects of the class) represent or do. The name should have an appropriate prefix (see “Prefixes”). The Foundation and Application Kit frameworks are full of examples; a few are NSString, NSDate, NSScanner, NSApplication, NSButton, and NSEvent.

Protocols should be named according to how they group behaviors:

Header Files

How you name header files is important because the convention you use indicates what the file contains:



< Previous PageNext Page > Hide TOC


Last updated: 2006-04-04




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice