Interfaces, Conceptually
Interfaces can be a difficult concept to grasp conceptually. To help make sense of the concept, consider these real world examples.
Let's talk about interfaces.
We should probably start with a brief description of what an interface is conceptually. The best way to do that is to clarify what an interface is not. An interface is not an implementation.
An interface is the what.
An implementation is the how.
An interface declares what an object will do. Think of it as a contract, a set of promises. An object that implements an interface must agree to this contract.
An implementation is one of many ways to fulfill that contract.
Real world examples
Interfaces can be a difficult concept to grasp conceptually. To help make sense of the concept, consider the following examples of the interface concept from everyday life.
Video game controllers
Consider a console system like the Xbox 360. This system comes with at least one controller. This controller has several standard inputs: two clickable analog joysticks; one four-way directional pad; two analog trigger buttons; two bumper buttons; four action buttons labeled "A", "B", "X", and "Y"; and three "other" buttons, "Back", "Start", and "Guide." You can think of this list of buttons as the controller interface.
Any implementation of the Xbox 360 controller must agree to this button list contract. But that still leaves room for lots of different implementations of the controller interface. What are some examples of these implementations? Well, they are all the different options available for purchase. Some are first-party offerings from Microsoft, but the existence of the interface also allows third-party manufacturers to come up with some wild options.
Telephones
Another example are landline, touch-tone phones. The interface requires only a microphone, speaker, twelve keys for 0-9, #, and *. Here again, the implementations abound.
Foundation laid
Hopefully, this brief overview of interfaces as a concept will help you understand how they can be useful in our programming. In future articles, I will go into more depth about when, why, and how to use interfaces to our advantage in VBA.
Image by Olya Adamovich from Pixabay