Having the classes functional and implementing the proper interface are important, but we are still missing the demonstrational code that shows why the interface is different from a class with only abstract methods in it. The answer is presented here, and it requires us to write a function that takes an interface (not a class) as a parameter.
In Java, we would write this as follows :
protected void ShowHTML( HTMLSource SomeObject )
{
System.out.println( SomeObject.GetHTML() );
}
The C# version would be nearly identical:
protected void ShowHTML( IHTMLSource SomeObject )
{
System.Console.Out.WriteLine( SomeObject.GetHTML() );
}
Now, in both Java and C#, we have a ShowHTML method that accepts any object that implements the HTMLSource interface. With this knowledge, it is safe for the preceding ShowHTML function to call the GetHTML method on the received object.
Figure 11-3 shows what our diagramming now looks like, with multiple classes that implement an interface.