提供接口类和其他接口实用程序。
good-interface的Python项目详细描述
良好的_接口
提供接口类和其他实用程序,这些实用程序可以定义方法“接口”,从而自动检查类和对象中的方法实现。
接口
接口是要在实现该接口的类中实现的方法的集合。接口类可以从类骨架定义接口。
fromgood_interfaceimportInterface@InterfaceclassMyInterface:defmethod1(self,arg1,arg2):passdefmethod2(self,arg2):pass
由于接口是可调用的,因此可以将新接口对象作为类的装饰器调用,该装饰器提供对给定类的检查,确保它在给定接口中实现定义的方法。
fromgood_interfaceimportInterface@InterfaceclassMyInterface:defmethod1(self,arg1,arg2):passdefmethod2(self,arg2):pass@MyInterfaceclassMyClass:defmethod1(self,arg1,arg2):passdefmethod2(self,arg2):pass
在另一个接口上调用该接口将扩展该接口,并将当前接口的方法添加到新接口中
fromgood_interfaceimportInterface@InterfaceclassMyInterface1:defmethod1(self):pass@MyInterface1@InterfaceclassMyInterface2:defmethod2(self,arg1,arg2):passdefmethod3(self,arg2):pass# Creates:## @Interface# class MyInterface2:# def method1(self):# pass## def method2(self, arg1, arg2):# pass## def method3(self, arg2):# pass