Let child classes change default values of parent properties#473
Let child classes change default values of parent properties#473t-kalinowski wants to merge 2 commits intomainfrom
Conversation
|
This is tricky when a parent class has a custom constructor, where the default value is essentially unknown, and implicitly different from I.e., this test: S7/tests/testthat/test-constructor.R Line 80 in b5cf389 @lawremi, let me know if you have any thoughts about how to resolve this. |
|
Is my understanding correct that initialization of properties with default values only happens through the constructor? If so, then it seems tricky to implement a custom constructor, as it will need to support overriding of defaults. One solution is the prototype idea, where the object starts with its default values. The constructor can always set them a second time, but just making sure they are set initially really simplifies the constructor contract. Or, we just tell the user that custom constructors is an expert-level feature. Personally, I would avoid the type of constructor in the cited test and just leave the conveniences to a separate, user-facing constructor. Leaving the actual constructor to low-level property setting is a much more cohesive approach. In the core of Bioc, we rarely if ever overrode |
|
Would be good to revisit this, as it keeps biting me. The test that fails should not be relevant, since the subclass is not actually overriding any properties. Obviously, overriding a property (like inheritance itself) is strong coupling, so if the parent starts doing weird things in the constructor, things are expected to break. |
closes #467