Refactor PackageContainer composition over inheritance#2324
Conversation
df70b51 to
a2a66b7
Compare
PackageContainerPackageContainer 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. |
wpbonelli
left a comment
There was a problem hiding this comment.
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 |
wpbonelli
left a comment
There was a problem hiding this comment.
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
PackageContainerto a composition pattern, rather than inheritance. Only 7 functions need to be duplicated inMFSimulationBase,MFPackage, andMFModelas 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,MFSimulationBaseof 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_dictpackage_dictpackage_namespackage_type_dictpackage_name_dictpackage_filename_dictI changed
MFPackage._simulation_datatoMFPackage.simulation_datato be consistent withMFSimulationBaseandMFModel. Also because it is used byoutput_util.MF6Output(line 115).Breaking changes
Static variables
modflow_packages,packages_by_abbr,modflow_models, andmodels_by_typeshould be called viaPackageContainer.modflow_packagesetc. If these variables are part of the public API, the users might need to change some code to no longer callMFPackage.modflow_packagesor 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.