TAILIEUCHUNG - Apress - Accelerated C#_2

Tham khảo tài liệu 'apress - accelerated c#_2', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 5 INTERFACES AND CONTRACTS In this example note a couple of things. First FancyComboBox lists lUIControl in its inheritance list. That s how you indicate that FancyComboBox is planning to reimplement the lUIControl interface. Had lUIControl inherited from another interface FancyComboBox would have had to reimplement the methods from those inherited interfaces as well. I also had to use the new keyword for because it hides . This wouldn t have been a problem had ComboBox implemented the method explicitly because it wouldn t have been part of the ComboBox public contract. When the compiler matches class methods to interface methods it also considers public methods of base classes. In reality FancyComboBox could have indicated that it reimplements IUIControl but without redeclaring any methods as the compiler would have just wired up the interface to the base class methods. Of course doing so would be pointless because the reason you reimplement an interface in a derived class is to modify behavior. Note The ability to reimplement an interface is a powerful one. It highlights the vast differences between the way C and the CLR handle interfaces and the C treatment of interfaces as abstract class definitions. Gone are the intricacies of C vtables as well as the question of when you should use C virtual inheritance. As I ve said before and don t mind saying again C CLR interfaces are nothing more than contracts that say You Mr. Concrete Class agree to implement all of these methods in said contract . interface. When you implement methods in an interface contract implicitly they must be publicly accessible. As long as they meet those requirements they can also have other attributes including the virtual keyword. In fact implementing the IUIControl interface in ComboBox using virtual methods as opposed to nonvirtual methods would make the previous problem a lot easier to solve as demonstrated in the following .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.