Polymorphism, in its simplest terms, is the ability for objects to be interchangeable in the code without breaking anything. In order to accomplish that, those objects must present common public interface members—the same accessible properties and methods—across the board. Ideally, those common interface members should be the only interface members as well, otherwise there is a risk of breaking the interchangeability of those objects. In a class-based structure, it's usually a good idea to have that interface defined as an individual abstraction—an ABC in Python, with or without concrete members. Consider the following collection of classes for making connections to and querying against various relational database backends:
Where:
-
BaseDatabaseConnector is an abstract class that requires a query method...