Summary


Classes and structures are very similar. Both are container types that group related variables, methods, and events in a single entity.

Most developers use classes exclusively, primarily because structures are relatively new and developers are more familiar with classes. Structures also have the additional restriction that they cannot take advantage of inheritance.

Another significant factor when picking between classes and structures, however, is their difference in type. Classes are reference types, while structures are value types. This gives them different behaviors when defining and initializing objects, and when passing objects to routines by value and by reference.

When you understand the differences between classes and structures, you can select the one that is more appropriate for your application.

If you build enough classes and structures, you may start to have naming collisions. It is common for developers working on different projects to define similar business classes such as Employee, Customer, Order, and InventoryItem. Although these objects may be similar, they may differ in important details. The Customer class defined for a billing application might include lots of account and billing address information, while a repair assignment application might focus on the customer’s equipment and needs.

Having two Customer classes around can result in confusion and programs that cannot easily interact with each other. Namespaces can help categorize code and differentiate among classes. You can define separate namespaces for the billing and repair assignment applications, and use them to tell which version of the Customer class you need for a particular purpose.

Chapter 17 describes namespaces in detail. It explains how to create namespaces and how to use them to refer to classes created in other modules.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net