Converging Multiple Classes
jeanmichel at sequans.com
Fri Feb 4 12:07:39 EST 2011
> I have a bunch of cameras I want to run tests on. They each have
> different drivers and interfaces. What I want to do is create python
> wrappers so that they all have a common interface and can be called by
> the same python test bench program. I'm not sure what to call it. I
> don't think it's inheritance. Maybe there is no official thing here
> and I just need to brute force my way through it. Is there some
> programming methodology I should be using?
I guess Interface/Abstract classes are what you are searching for.
# Camera is the interface/abstract base class of all cameras.
# it defines all the function that a Camera needs to implement.
# This code is common to all Cameras
# an abstract method raises NotImplementedError and does not
# however it indicates to all child classes what they need to
# One implementation of a Camera
print 'I am implementing the shutdown for that very specific
print 'Shutting down with the proper implementation'
Now here is what you test bench whould look like:
from camera import ATypeOfCamera, AnotherTypeOfCamera
for cameraType in [ATypeOfCamera, AnotherTypeOfCamera]:
myCam = cameraType()
More information about the Python-list