106Microsoft Visual Studio 2010: A Beginner’s Guide
Figure 4-3 The C# interface snippet template
invokes the Credit method on the runtime Checking or Saving instance. Your code that you wrote for Checking.Credit and Saving.Credit will execute as if your code called them directly as in Listing
Now you can see that interfaces help you treat different types of objects as if they were the same type and helps you simplify the code you need to write when interacting with those objects, eliminating duplication. Imagine what would happen if you were tasked with adding more bank account types to this algorithm without interfaces; you would need to go into the algorithm to write duplicate code for each account type. However, now you can create the new account types and derive them from IAccount; the new account types automatically work in the same algorithm.
The interface Snippet
Before using the interface snippet, open a new file by
Because prefixing interfaces with I is an expected convention, the template highlights the identifier after I.