-
Notifications
You must be signed in to change notification settings - Fork 314
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
Refactor PackageContainer
composition over inheritance
#2324
Conversation
df70b51
to
a2a66b7
Compare
PackageContainer
PackageContainer
composition over inheritance
My sense after the discussion today is that where we are unclear if an API is meant to be user-facing, we can keep it intact and add a deprecation warning, which will (we hope) give us an idea whether anyone is using it — if not, after some period (how long?) it is fair game for pre-v4 refactoring? |
@wpbonelli Should I also add deprecation warnings for the class variables |
I've never used any of those variables you listed under "breaking changes". If it requires additional work to issue a deprecation warning, then my opinion is that you can just rename/remove them, especially if none of the tests or examples use them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can confirm none of
- modflow_packages
- packages_by_abbr
- modflow_models
- models_by_type
are used in flopy tests, mf6 tests, or mf6 examples
@wpbonelli I have remove usages in the tests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good just a few things
Ensure to keep the API in place for MFModel, MFPackage and MFSimulationBase
Because it's used outside of the class
Because it is used outside of the class
No one seems to be using it. We will need to find other ways to fix the tests.
3f67021
to
e8cd8d9
Compare
In preparation of larger refactor works in flopy, we discussed with @wpbonelli and @mjreno that it would be beneficial for readability to change the
PackageContainer
to a composition pattern, rather than inheritance. Only 7 functions need to be duplicated inMFSimulationBase
,MFPackage
, andMFModel
as pass-through functions. There should be no compatibility issues for the users, as the signature hasn't changed.My doubts
There are some public API functions that are now part of
MFPackage
,MFModel
,MFSimulationBase
of which I doubt if we should keep them. They don't seem to be called in any tests and I wonder if they should be available. The function that seems reasonable to keep is therefore onlyget_package
, and maybe only forMFSimulationBase
.package_key_dict
package_dict
package_names
package_type_dict
package_name_dict
package_filename_dict
I changed
MFPackage._simulation_data
toMFPackage.simulation_data
to be consistent withMFSimulationBase
andMFModel
. Also because it is used byoutput_util.MF6Output
(line 115).Breaking changes
Static variables
modflow_packages
,packages_by_abbr
,modflow_models
, andmodels_by_type
should be called viaPackageContainer.modflow_packages
etc. If these variables are part of the public API, the users might need to change some code to no longer callMFPackage.modflow_packages
or the like.It is possible to make this a non-breaking change by introducing a meta-class, but if possible the user does not need these attributes, I would try to not take this route.