I am from a Java background and now working on a django application. Need your input if I am in the wrong direction.
I am trying to implement zope.interface.Interface in my Django application and trying to achieve what interfaces in Java do, but it does not throw any error if the implementer class does not provide the definition of all the methods in the interface.
Here is my sample implementation.
import zope.interface
class MyInterface(zope.interface.Interface):
x = zope.interface.Attribute("foo")
def method1(self, x):
pass
def method2(self):
pass
@zope.interface.implementer(MyInterface)
class MyClass:
def method1(self, x):
return x**2
def method2(self):
return "foo"
@zope.interface.implementer(MyInterface)
class MyClass2:
def method1(self, x):
return x**2
print(list(zope.interface.implementedBy(MyClass)))
print(list(zope.interface.implementedBy(MyClass2)))
c = MyClass()
print(c.method1(5))
print(c.method2())
d = MyClass2()
print(d.method1(5))
Kindly help me find out what am I doing wrong and your kind guidance.
Thank you,