-
Notifications
You must be signed in to change notification settings - Fork 21
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
Implement Base classes as AbstractBaseClasses #31
Comments
This is a good idea that has been on my wishlist for a while |
I have already started doing this on a local branch, I will make a draft pull request so you can track my progress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python supports abstract base classes (ABCs) through the
abc
module in stdlib. This allows you to mark methods that should be overloaded by child classes as such by using the@abstractmethod
decorator.The advantages of this are the following:
TypeError
that the class is not meant to be instantiated directly.AquiferData.isinside
method is marked as abstract, and should therefore be explicitly overloaded byAquifer
. However, theAquifer
class can explicitly subscribe to the default implementation to return True. For the inhomogeneities the default behaviour isn't appropriate and can be implemented as necessary. ForElement.potinf
it doesn't make sense to provide a default implementation, so the abstract version can simply containpass
.An example where this could be used is
AquiferData
. By changing this:to
you get the same principle, but stricter enforcement.
As an example how these classes work:
produces this output:
The text was updated successfully, but these errors were encountered: