Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,看了这个抽象基类的代码,想请教个问题 #1

Open
ghost opened this issue Feb 18, 2022 · 0 comments
Open

你好,看了这个抽象基类的代码,想请教个问题 #1

ghost opened this issue Feb 18, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 18, 2022

抽象基类总的来说和接口类似,是一个“不完整的”类,因为其内部可以有已经实现的方法,也有需要子类重新写的方法。但是我也可以定义一个父类,在父类中定义一个方法,但是只是定义,然后在方法中使用如下代码抛出异常,当子类中没有定义该方法的时候就会报错,提示子类中必须提供该方法,这种和抽象基类的应用是否存在冲突呢?或者说是都能实现,只是方式不同罢了?

raise NotImplementedError(
'subclasses of SiteBase must provide an find() method')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants