Virtual function in Python class : Class Virtual « Class « Python






Virtual function in Python class

Virtual function in Python class


class SpecialCase:
    def amethod(self): 
       print "special"

class NormalCase:
    def amethod(self): 
       print "normal"

def appropriateCase(isnormal=1):
    if isnormal: 
       return NormalCase()
    else: 
       return SpecialCase()

aninstance = appropriateCase(isnormal=0)
aninstance.amethod()


           
       








Related examples in the same category

1.Override predefined functionOverride predefined function
2.Virtual function: extend method behaviourVirtual function: extend method behaviour
3.Virtual function in PythonVirtual function in Python
4.Virtual function in two base classVirtual function in two base class
5.Virtual function in derived class is calledVirtual function in derived class is called