Without knowing in what context you read it I'll take a stab and suggest
that it refers to the code used to implement an interface.
Just to give you a little bit of grounding on the subject, a class is
characterized by its public methods and properties. When you write code
that accesses a class through its methods the compiler uses the class name
and method name along with the number and type of parameters to decide how
to call the code inside the class. It is possible for two classes, having
different names, to have common method names. For example class A might
have a method called foo and class B. might also have a method similarly
called foo.
public class A
public sub foo()
'do stuff
end sub
end class
public class B
public sub foo()
'do different stuff
end sub
end class
In this case it is possible to call a.foo or b.foo but notice that in both
of these cases the class name and the method name go together to make a
unique calling address for the compiler and so in reality the two methods
even though they have the same name have nothing whatsoever in common and
are not bound to behave in a similar manner.
In many cases however, it is desirable to create a method name that means
something, such as "draw" or "sort" and know that when the method is called
a certain behavior will be carried out. This is where interfaces come in
handy.
An interface is the declaration of a "public face" that can be, if you will,
stuck on to any number of classes so that all of those classes, regardless
of their other functional behaviors, will always support the properties and
methods defined in the interface. It's a kind of contract of behavior
between what might otherwise be wildly dissimilar classes.
public interface IFoo
sub foo()
end interface
Note how an interface declaration never has any real code in it. It just
declares the names, parameters and return types of each of the methods and
possibly the types and accesses of properties.
Now, it is possible to make any number of classes that "implement" this
interface and so the method name will maintain its meaning across all of the
classes that use it.
class A
implements IFoo
public sub foo() Implements IFoo.foo
'do stuff
end sub
end class
class B
implements IFoo
public sub foo() Implements IFoo.foo
'do stuff
end sub
end class
These new declarations may look very similar to the ones you saw earlier
however there is one important difference between them. It is possible now
to take either one of those classes and extract from it an IFoo interface
that is guaranteed to have the foo method in it and both of those classes
will be expected, by contract, to behave in a clearly defined manner.
dim x as IFoo
dim classa as A=new A()
dim classb as B=new B()
x=ctype(classa, IFoo)
x.foo()
x=ctype(classb, IFoo)
x.foo()
Note that a class which declares it implements an interface must provide
concrete implementations for all of the methods and properties the interface
describes. It is this code, designated "do stuff" in the example above that
is called "implementation code"
A classic example of an interface that you might use all of the time is the
ICollection Interface that is implemented by all of the collection classes
in .net. This interface allows any class to provide enumeration behavior
which is used extensively in data binding.
--
Bob Powell [MVP]
C#, System.Drawing
The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at
http://bobpowelldotnet.blogspot.com