Problem with method overriding from base class

Dominique.Holzwarth at ch.delarue.com Dominique.Holzwarth at ch.delarue.com
Mon Mar 31 05:05:39 EDT 2008


Hello everyone

I have defined some sort of 'interface class' and a factory function that creates instance objects of specific classes, which implement that interface:

Interface definition:
***************************************************************************************
import GUI.webGUI as webGUI

class EditInterface(webGUI.WebGUI):
    def addEntry(self, *p):
        raise 'EditInterface.addEntry(): Interface must not be called directly'
    def clearScreen(self, *p):
        raise 'EditInterface.clearScreen(): Interface must not be called directly'
    def deleteEntry(self, *p):
        raise 'EditInterface.deleteEntry(): Interface must not be called directly'
    def editEntry(self, *p):
        raise 'EditInterface.editEntry(): Interface must not be called directly'
    def processUserInput(self, *p):
        raise 'EditInterface.processUserInput(): Interface must not be called directly'
    def show(self, entry, statustext):
        raise 'EditInterface.show(): Interface must not be called directly'
***************************************************************************************

Factory:
***************************************************************************************
def factory(type, *p):
    if type == common.databaseEntryTypes[0]:
        return module1.Class1(*p);
    elif type == common.databaseEntryTypes[1]:
        return module2.Class2(*p);
    elif type == common.databaseEntryTypes[2]:
        return module3.Class3(*p);
    elif type == common.databaseEntryTypes[3]:
        return module4.Class4(*p);
***************************************************************************************

Implementing Class1:
***************************************************************************************
import editInterface

class Class1(editInterface.EditInterface):

    def __init__(self, product, database):
        # do something here ...

    def showEntry(self, entry, statustext):
        # do something here as well, return some string...
***************************************************************************************

Now, when I want to create an Instance of Class1 I do:

myClass1Instance = factory.factory(common.databaseEntryTypes[1], 'Name', databaseObj )

Which seems to work fine according to the debugger. But when I do next:

msg = myClass1Instance.show(firstEntry, '')

Then the show() method of the class 'EditInterface' is called instead of the show() method of the class 'Class1' !!
Does anyone have an idea why the method of the base class is called instead of the method of the derived class and how can I do it, so that the show() of Class1 is called instead?

Greetings
Dominique

(did some data hiding there, but shouldn't really matter for the problem ;-))




More information about the Python-list mailing list