Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Converging Multiple Classes

Reply
Thread Tools

Converging Multiple Classes

 
 
Wanderer
Guest
Posts: n/a
 
      02-04-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?

Thanks
 
Reply With Quote
 
 
 
 
Jean-Michel Pichavant
Guest
Posts: n/a
 
      02-04-2011
Wanderer wrote:
> 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?
>
> Thanks
>

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.
class Camera(object):
def printCameraType(self):
# This code is common to all Cameras
print self.__class__.__name__

def shutdown(self):
# an abstract method raises NotImplementedError and does not
implement anything
# however it indicates to all child classes what they need to
implement.
raise NotImplementedError()

# One implementation of a Camera
class ATypeOfCamera(Camera):
def shutdown():
print 'I am implementing the shutdown for that very specific
Camera type'
return 0

class AnotherTypeOfCamera(Camera):
def shutdown():
print 'Shutting down with the proper implementation'
return 0


Now here is what you test bench whould look like:

from camera import ATypeOfCamera, AnotherTypeOfCamera

for cameraType in [ATypeOfCamera, AnotherTypeOfCamera]:
myCam = cameraType()
myCam.printCameraType()
myCam.shutdown()

JM
 
Reply With Quote
 
 
 
 
Wanderer
Guest
Posts: n/a
 
      02-04-2011
On Feb 4, 12:07*pm, Jean-Michel Pichavant <(E-Mail Removed)>
wrote:
> Wanderer wrote:
> > 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?

>
> > Thanks

>
> 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.
> class Camera(object):
> * * def printCameraType(self):
> * * * *# This code is common to all Cameras
> * * * *print self.__class__.__name__
>
> * * def shutdown(self):
> * * * *# an abstract method raises NotImplementedError and does not
> implement anything
> * * * *# however it indicates to all child classes what they need to
> implement.
> * * * *raise NotImplementedError()
>
> # One implementation of a Camera
> class ATypeOfCamera(Camera):
> * * def shutdown():
> * * * *print 'I am implementing the shutdown for that very specific
> Camera type'
> * * * *return 0
>
> class AnotherTypeOfCamera(Camera):
> * * def shutdown():
> * * * *print 'Shutting down with the proper implementation'
> * * * *return 0
>
> Now here is what you test bench whould look like:
>
> from camera import ATypeOfCamera, AnotherTypeOfCamera
>
> for cameraType in [ATypeOfCamera, AnotherTypeOfCamera]:
> * * myCam = cameraType()
> * * myCam.printCameraType()
> * * myCam.shutdown()
>
> JM


Thanks JM. That help a lot.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A reminder of just how bad converging verticals can look ... Bruce Digital Photography 3 02-07-2011 05:37 PM
Converging verticals Laurie Digital Photography 13 11-30-2006 08:53 PM
Beginner Help: Joining Multiple classes in multiple files? JHenstay C++ 3 01-11-2004 02:28 PM
How do I correct converging verticals ? Barry Smith Digital Photography 16 12-12-2003 01:06 AM
Converging verticals Stewy Digital Photography 1 10-14-2003 12:33 AM



Advertisments