tailieunhanh - Visual Basic .NET The Complete Reference phần 6
Theo ý kiến của tôi, bạn không nên khai báo biến lớp học nếu bạn không cần phải, Tuy nhiên, lỗi thứ hai là phổ biến hơn, bởi vì nó không phải là khó khăn để vô tình tham khảo một yếu tố vượt ra ngoài trên ràng buộc của mảng, đặc biệt là khi bạn sử dụng các con số kỳ diệu trong mã của bạn. | Abstract Class or Explicit Interface Interfaces can and should be used for developing classes in situations where inheritance of implementation from base or parent classes is not required. Class hierarchies is-a relationships and interface declaration and implementation serve very different design requirements. Interfaces can and should be used in situations that call for interface implementation. A good example is the Structure Value Types that cannot inherit implementation via standard class inheritance see Chapter 9 . Interfaces should not be used as a substitute for the lack of multiple inheritance. That s not the premise for their inclusion in the .NET Framework or any other object-oriented framework. Multiple inheritance does not have its place in the .NET Framework interfaces do and have nothing to do with multiple inheritance. This is further discussed in this chapter. Also see Inheritance and Multiple Inheritance in Chapter 9. Interfaces are great for structure and formality in a classgreat tools for class providers to force conformance by class consumers. If your classes seem like badly packed jumbled up holiday suitcases the whole family s togs tossed into one bag then it s in need of the structuring that interfaces provide. Finally and most importantly interfaces allow you to delegate. This is probably their most advanced and useful purpose. By being able to collaborate with an interface that is a bridge to an autonomous class that implements the interface the client to the interface has a way of targeting the implementation. By being totally decoupled from the class that references the interface and the class that implements it the client class can use an interface to delegate functionality to classes specially designed to play certain roles for them. In other words rather than working under is-a relationships classes collaborate on the basis of being able to play the role of something else. And the interface a form of delegate or agent is the middle .
đang nạp các trang xem trước