-
Notifications
You must be signed in to change notification settings - Fork 0
Abstract Methods
Vinicius Reif Biavatti edited this page Jul 25, 2022
·
5 revisions
- Always use the
@abstractmethod
as the decorator for required abstract methods - For non-required abstract methods, use the
pass
or docstring in the implementation - For required abstract methods, raise a
NotImplementedError
error as default implementation
✅ Do
class Building(ABC):
# Non-required
def destroy(self) -> None:
pass
# Required
@abstractmethod
def build(self) -> None:
raise NotImplementedError()
❌ Don't
class Building(ABC):
# Needs implementation without @abstractmethod
def build(self) -> None:
raise NotImplementedError()
# Required but does not raises an error
@abstractmethod
def build(self) -> None:
pass
- Home
- Structural Naming Conventions
- Format Conventions
- Code Naming Conventions
- Inheritance
- Access Modifiers
- Importation
- Functions and Methods
- Documentation
- Resources