Skip to content

Instantly share code, notes, and snippets.

The problem

I have a couple of classes which each control slightly different versions of a similar class of device. I would like to be able to create objects that control these devices all form the same interface. Below is an example of the current behavior and an example of what I would like. I would like to avoid a bunch of if else statements in the classes so I would prefer to have some way to select which subclass on initialization of the ITLA object. The reason for this is primarily for clarity and readability of the code. The classes all share the same functions but have slightly different implementations of certain functions. These implementations are mutually incompatible and can cause errors or undesired behavior when one class is