tailieunhanh - microsoft visual c 2008 step by step phần 5

Khi bạn thực hiện một giao diện, bạn phải đảm bảo rằng mỗi phương pháp phù hợp với phương pháp giao diện tương ứng của nó một cách chính xác, theo quy tắc sau đây: tên phương pháp và các loại trả lại phù hợp với chính xác. Bất kỳ các thông số (bao gồm cả ref và bổ từ khóa trong) phù hợp với chính xác. | 242 Part II Understanding the C Language When you implement an interface you must ensure that each method matches its corresponding interface method exactly according to the following rules The method names and return types match exactly. Any parameters including ref and out keyword modifiers match exactly. The method name is prefaced by the name of the interface. This is known as explicit interface implementation and is a good habit to cultivate. All methods implementing an interface must be publicly accessible. However if you are using explicit interface implementation the method should not have an access qualifier. If there is any difference between the interface definition and its declared implementation the class will not compile. The Advantages of Explicit Interface Implementations Implementing an interface explicitly can seem a little verbose but it does offer a number of advantages that help you to write clearer more maintainable and more predictable code. You can implement a method without explicitly specifying the interface name but this can lead to some differences in the way the implementation behaves. Some of these differences can cause confusion. For example a method defined by using explicit interface implementation cannot be declared as virtual whereas omitting the interface name allows this behavior. It s possible for multiple interfaces to contain methods with the same names return types and parameters. If a class implements multiple interfaces with methods that have common signatures you can use explicit interface implementation to disambiguate the method implementations. Explicit interface implementation identifies which methods in a class belong to which interface. Additionally the methods for each interface are publicly accessible but only through the interface itself. We will look at how to do this in the upcoming section Referencing a Class Through Its Interface. In this book I recommend implementing an interface explicitly wherever .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.