Created
September 6, 2013 08:20
-
-
Save datakop/6460975 to your computer and use it in GitHub Desktop.
Abstract classes in Pyhton.
Decorator implementation for pure virtual functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# decorator | |
def pure_virtual(func): | |
def closure(*dt, **mp): | |
raise NotImplementedError("Method %s is pure virtual" % func.__name__) | |
return closure | |
class Abstarct(object): | |
""" Abstract class Class """ | |
@pure_virtual | |
def virtual_method(self): pass # Empty Virtual method | |
# >>> Abstarct().virtual_method() | |
# Traceback (most recent call last): | |
# File "abstr.py", line .., in <module> | |
# Abstarct().virtual_method() | |
# File "abstr.py", line .., in closure | |
# raise NotImplementedError("Method %s is pure virtual" % func.__name__) | |
# NotImplementedError: Method virtual_method is pure virtual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment