TAILIEUCHUNG - Pro VB 2005 and the .NET 2.0 Platform Second Edition phần 3

Sử dụng NUnit, bạn có thể tạo điều kiện thuận lợi cho việc thử nghiệm các mã quản lý của bạn. Sự thất vọng của nhiều người, Microsoft đã chọn để tích hợp khả năng sắp xếp cho Visual Basic 2005 dự án. Các tin tốt là tự do tải về plug-in cho phép Visual Basic 2005 | 170 CHAPTER 6 UNDERSTANDING INHERITANCE AND POLYMORPHISM This class cannot be extended Public NotInheritable Class MiniVan Inherits Car End Class If you or a teammate were to attempt to derive from this class you would receive a compiletime error Error Cannot extend a class marked NotInheritable Public Class TryAnyway Inherits MiniVan End Class Formally speaking the MiniVan class has been sealed. Most often sealing a class makes the most sense when you are designing a utility class. For example the System namespace defines numerous sealed classes etc. . You can verify this for yourself by opening up the Visual Studio 2005 Object Browser via the View menu and selecting the type defined within in Figure 6-1 the use of the NotInheritable keyword. Figure 6-1. The base class libraries define numerous sealed types. Thus just like the MiniVan if you attempted to build a new class that extends you will receive a compile-time error Another error Cannot extend a class marked NotInheritable Public Class MyConsole Inherits Console End Class Note In Chapter 4 you were introduced to the structure type. Structures are always implicitly sealed. Therefore you can never derive one structure from another structure a class from a structure or a structure from a class. CHAPTER 6 UNDERSTANDING INHERITANCE AND POLYMORPHISM 171 As you would guess there are many more details to inheritance that you will come to know during the remainder of this chapter. For now simply keep in mind that the Inherits keyword allows you to establish base derived class relationships while the NotInheritable keyword prevents inheritance from occurring. Revising Visual Studio 2005 Class Diagrams Back in Chapter 2 I briefly mentioned that Visual Studio 2005 now allows you to establish base derived class relationships visually at design time. To leverage this aspect of the IDE your first step is to include

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.