posted 18 years ago
Among other things, this helps separate things that change from things that don't change, making the code easier to maintain and less prone to breaking.
For example, you might have a method that takes a Pizza reference. As fred pointed out, this will accept any type of Pizza, so you only need one method. But this is also code that doesn't change, so you can continue to invent new types of pizzas (things that might change), and you won't need to update the method.
For this to work, note that the interface is a type of "contract" that guarantees implementing classes will have certain methods available. For example, whenever you create a new class that implements Pizza, instances of that new class are guaranteed to behave like any other Pizza, exactly as expected by a method that takes a Pizza reference.
[ November 27, 2006: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org