Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

Namespaces Versus Naming Conventions

As you have been going through the samples in this chapter, you might have noticed that the C# classes always exist within a namespace. Namespaces in C# are designed specifically to avoid naming collisions as well as to aid in organizing hierarchies of logically connected classes, enums, and structs.

In Objective-C and throughout all of Apple's libraries, either for the iPhone or for traditional Mac development, you will see that there are no namespaces. The decision was made for Objective-C to not support the concept of namespaces (which are available in many OOP languages, including C# and C++). Instead, Apple has opted for a standard by which classes belonging to a particular family, purpose, product, or company all begin with a common two-letter prefix in all capital letters.

For example, a combatant class written by someone named Kevin Hoffman might actually be called KHCombatant rather than simply Combatant. Further, that same class written by a company called Exclaim Computing might be written as ECCombatant or XCCombatant.

Naming collisions within iOS applications are rare because you will encounter these collisions only if your application is making use of a library, framework, or class that contains classes named identically to yours. The rare chances of naming collisions in this situation are usually eliminated with the use of the two-letter prefix naming convention.

  • + Share This
  • 🔖 Save To Your Account