-
Notifications
You must be signed in to change notification settings - Fork 456
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
allow addModule method that will not allow a 2nd override of the same interface #628
Conversation
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.
Thanks. I was not able to actually test the changes due to temporarily missing my dev environment (my laptop is in treatment for a new battery), but by looking at the code changes it looks reasonable. Also, thanks for adding tests, they look fine and are implemented in a way as I would have done based on how I understood the problem at the DevMtg.
Thanks.
After having thought about this, I am now wondering if we should not make this the default. I had now one or two cases where two different contribs overwrote each other, and this indeed either goes totally unnoticed, or leaves users baffled.
My intuition would be to
(1) change "addOverridingModule" to that new behavior. The syntax would not be totally wrong, since it would still override the default settings for the matsim extension points.
(2) add a method
addOverridingModule( boolean allowMultipleOverrides, AbstractModule module )
that could be used to explicitly ask for the old behavior. (Clearly, could also have a differently named second method, but I find such a switch not so stupid for testing one version against the other.)
|
To me, the phrasing
sounds a little strange. I'm a little bit afraid that this change would also break many peoples' code who rely on the API without being that much more useful. |
Joschka, could you please explain a bit more, I don't understand, in part because your inclusion of my material is incomplete. Questions: |
Mhm. I agree for the default modules.
But what happens if we have
? I'm just a little bit concerned that this could confuse people even more. But maybe it's not such an issue. |
I see, thanks for clarifying that. My intuition is that it would be possible to have a contrib set additional modules, and then allow user code to override them once (case 1). My intuition also is that it would be more difficult to have a contrib override an already existing core module, and then allow user code to override it again, but only once (case 2). Is case 2 an issue with drt? If not, we could think about an implementation for case 1. |
I don't think case 2 is an issue. |
I also think
The question would be what does once mean. Either throw and error at the second attempt or print a clear warning that this can be dangerous. @jfbischoff What would be a concrete use case of "case 1" where DRT overrides some default bindings? |
In several of our setups, we need addOverridingModule(...) at more than one level, so I would like to keep that as an option at least for the time being. I could probably live with a warning. I could probably even live with a config switch where such behavior explicitly needs to be switched on.
|
I think the default DRT configuration does not need any overriding at all (it does not override the core matsim). However, e-DRT overrides two EV bindings, but that should be easy to change. As for limiting the number of overriding modules, I suggest some transition period when this limit is not imposed, so that we can gradually get rid of overriding modules and then see what is left. |
…default, and have instead an "addFullyOverridingModule" to reflect the previous behavior.
I tried to code what we debated: a
controler.addModule(...)
method that would enforce internal consistency between modules.The idea with this method is that: (1) one can override matsim defaults, but (2) one cannot override them a second time.
The behavior should be the same as
except that the syntax now is
Evidently, the main usecase is where these modules are added in different methods or classes ... we certainly have that with our hierarchical approach in Berlin, where run classes use
configureControler(...)
methods before adding additional material into the controler.There is also a test class,
MultipleOverridesOfSameBinding
, which is testing this. I can't say how far it goes and/or if it will fail eventually.I also can't say how it will deal with multiple overrides of the multibinders, e.g. when someone adds a disutility for the same mode again.
I am adding it as a PR for discussion ...