实现相同抽象方法的函数(采用不同参数)的参数列表

2024-06-28 11:17:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在SamplePArent类中有一个抽象方法

Class SampleParent
 @abc.abstractmethod
 def getData(Self, **kwargs)

它在3个不同的子类(A、B和C)中实现。在所有三个子类中,getData方法采用不同的参数。你知道吗

父类以及所有3个子类中getData方法的参数列表将是什么,以便保留抽象的概念。你知道吗

Class A
 def getData(self,null) # takes no parameter

Class B
 def getData(self, count) # takes integer value as a parameter

Class C
 def getData(self, name_dict) # takes dictionary as a parameter

所有函数定义的参数列表是否正确。我在parent方法中给出了**kwargs,因为它的3个实现方法都采用了不同类型的参数或没有参数。你知道吗


Tags: 方法self列表参数parameterdefas子类