This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Both of the lines you have written are accepted by the compiler. The advantage of this:
is that you can use any Product implementation. For example, maybe you have class Soda that implements Product, and class Cheese that also implements Product. You could write both of these two lines, and the compiler would allow them, because both classes 'are' products:
Then presuming that the Product interface has a getPrice() method, we can do this:
Now, a real advantage of this is that if we define another Product implementation later, say Cigarette, we could slot that into the code at the definition line, and all would be well:
We would not have to change any other code because the compiler simply expects a product, and that is what we have given it. We know that the getPrice will still work because all Products have this method, and Cigarette is a product.
Being able to change the exact implementation like this is known as Polymorphism and is one of the inherent advantages of interfaces.