Why Are Namespaces So Useful?

The purpose of namespaces is to enable a better organization of types. Regarding this, there are situations in which an object’s hierarchy could expose two different types with different behaviors but with the same name. For example, imagine you have two Person classes; the first one should represent a business contact, and the second one should represent your friends. Of course, you cannot create two classes with the same name within one namespace. Because of this, you can organize such types in different namespaces avoiding conflicts. The code in Listing 9.2 shows how you can define two Person classes within two different namespaces.

Listing 9.2 Avoiding Conflicts with Different Namespaces

This is the way how ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.