Interface
An abstraction. Used when there are interchangeable classes that provide similar functionality to the calling code.
Let’s start with a simple interface:
| |
And use the example below:
| |
With the two code samples above, the below hypothetical writers are possible:
| |
Note how handleLoopUpdates does not know or care what kind of logger it receives. The only thing handleLoopUpdates knows about is the Logger interface, and what the interface defines.