Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Commonmark migration
Source Link

I have been reading up on the distinction between virtual vs abstract methods. This is well documented. Difference between virtual and abstract methods

Virtual methods have an implementation and provide the derived classes with the option of overriding it.

Abstract methods do not provide an implementation and force the derived classes to override the method.

So, abstract methods have no actual code in them, and subclasses HAVE TO override the method.

Based on these statements, it sounds like methods decorated with abc.abstractmethod should have no implementation, only either pass, ... (used in abc docs), or raise NotImplementedError.


It seems programmers commonly use abc.abstractmethod to implement a virtual function, where overriding is mandatory. This can be seen in many places:

However, this seems to go against the very definition of the design pattern for abstract methods having no body.

This answer makes a good point on the subject matter.


My observation is the virtual vs abstract method design pattern is currently loosely followed in Python.

Can anyone shed light on this? What is the best practice?

I have been reading up on the distinction between virtual vs abstract methods. This is well documented. Difference between virtual and abstract methods

Virtual methods have an implementation and provide the derived classes with the option of overriding it.

Abstract methods do not provide an implementation and force the derived classes to override the method.

So, abstract methods have no actual code in them, and subclasses HAVE TO override the method.

Based on these statements, it sounds like methods decorated with abc.abstractmethod should have no implementation, only either pass, ... (used in abc docs), or raise NotImplementedError.


It seems programmers commonly use abc.abstractmethod to implement a virtual function, where overriding is mandatory. This can be seen in many places:

However, this seems to go against the very definition of the design pattern for abstract methods having no body.

This answer makes a good point on the subject matter.


My observation is the virtual vs abstract method design pattern is currently loosely followed in Python.

Can anyone shed light on this? What is the best practice?

I have been reading up on the distinction between virtual vs abstract methods. This is well documented. Difference between virtual and abstract methods

Virtual methods have an implementation and provide the derived classes with the option of overriding it.

Abstract methods do not provide an implementation and force the derived classes to override the method.

So, abstract methods have no actual code in them, and subclasses HAVE TO override the method.

Based on these statements, it sounds like methods decorated with abc.abstractmethod should have no implementation, only either pass, ... (used in abc docs), or raise NotImplementedError.


It seems programmers commonly use abc.abstractmethod to implement a virtual function, where overriding is mandatory. This can be seen in many places:

However, this seems to go against the very definition of the design pattern for abstract methods having no body.

This answer makes a good point on the subject matter.


My observation is the virtual vs abstract method design pattern is currently loosely followed in Python.

Can anyone shed light on this? What is the best practice?

Source Link

Python does abstractmethod containing non-empty body violate intended virtual/abstract design pattern?

I have been reading up on the distinction between virtual vs abstract methods. This is well documented. Difference between virtual and abstract methods

Virtual methods have an implementation and provide the derived classes with the option of overriding it.

Abstract methods do not provide an implementation and force the derived classes to override the method.

So, abstract methods have no actual code in them, and subclasses HAVE TO override the method.

Based on these statements, it sounds like methods decorated with abc.abstractmethod should have no implementation, only either pass, ... (used in abc docs), or raise NotImplementedError.


It seems programmers commonly use abc.abstractmethod to implement a virtual function, where overriding is mandatory. This can be seen in many places:

However, this seems to go against the very definition of the design pattern for abstract methods having no body.

This answer makes a good point on the subject matter.


My observation is the virtual vs abstract method design pattern is currently loosely followed in Python.

Can anyone shed light on this? What is the best practice?

lang-py

AltStyle によって変換されたページ (->オリジナル) /