Abstract Base Class without ABC
examples/oop/abc/no_abc.py
class NotImplementedError(Exception): pass class Base(): def foo(self): raise NotImplementedError() def bar(self): raise NotImplementedError() class Real(Base): def foo(self): print('foo in Real') def bar(self): print('bar in Real') def other(self): pass class Fake(Base): def foo(self): print('foo in Fake') r = Real() r.foo() r.bar() f = Fake() f.foo() f.bar()
foo in Real bar in Real foo in Fake Traceback (most recent call last): File "no_abc.py", line 28, in <module> f.bar() # NotImplementedError File "no_abc.py", line 9, in bar raise NotImplementedError() __main__.NotImplementedError