Defining Interfaces

 <  Day Day Up  >  

An interface defines a contract that a type fulfills when it implements the interface. The type must supply an implementation for all the members of the interface ”the interface provides no implementation of its own. An interface is defined using the Interface keyword. Interfaces may only contain methods, events, and properties. Methods and properties that appear in an interface declaration do not have a body, because they do not have an implementation in the interface. Also, members of interfaces never specify an access level, because they are always implicitly Public .

For example, the following declaration defines an ISizeable interface that defines a number of capabilities that a type that has a size should support.

 Interface ISizeable   ReadOnly Property Height() As Integer   ReadOnly Property Width() As Integer   Sub Resize(ByVal NewWidth As Integer, ByVal NewHeight As Integer)   Event Resized(ByVal NewWidth As Integer, ByVal NewHeight As Integer) End Interface 

The Height and Width properties will return the size, while the Resize method will change the size. When the size are changed, the Resized event will be fired .

Style

By convention, all interface names start with the uppercase letter I .


 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net