Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
, kể từ khi sự tách biệt của giao diện từ việc thực hiện của nó là cốt lõi của lập trình hướng đối tượng và thiết kế. Kể từ khi phương pháp này được khai báo là công cộng, đó là có sẵn cho bất kỳ mã bên ngoài lớp học, bao gồm các ứng dụng khác có thể sử dụng lắp ráp. | Chapter 5 To include a method as part of your interface you can simply declare a Public routine Public Sub AMethod Simpo PDF EMerge and Split Unregistered Version - http www.simpopdf.com Notice that there is no code in this routine. Any code would be implementation and is not part of the interface. Only the declaration of the method is important when discussing interfaces. This can seem confusing at first but it is an important distinction since the separation of the interface from its implementation is at the very core of object-oriented programming and design. Since this method is declared as Public it is available to any code outside the class including other applications that may make use of the assembly. If the method has a property you can declare it as part of the interface by using the Property keyword Public Property AProperty As String End Property You can also declare events as part of the interface by using the Event keyword Public Event AnEvent Finally you can include actual variables or attributes as part of the interface Public AnInteger As Integer This is strongly discouraged because it directly exposes the internal variables for use by code outside the class. Since the variable is directly accessible from other code you give up any and all control over the way the value may be changed or by which code may be accessed. Rather than making any variable Public it is far preferable to make use of a Property method to expose the value. In that way you can implement code to ensure that your internal variable is only set to valid values and that only the appropriate code has access to the value based on your application s logic. Using the Native Interface In the end the native or primary interface for any class is defined by looking at all the methods properties events and variables that are declared as anything other than Private in scope. This includes any methods properties events or variables that are inherited from a base class. You re used to .