-
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
[Core] Clean public API of components #4943
base: master
Are you sure you want to change the base?
Conversation
I call that 'un doigt dans l'engrenage', nice ! I totally agree on the fact that those methods should be final otherwise the 'delegate' pattern used here makes no sense because we cannot trust it for child class... But then I don't fully agree on the protected part : it might become cumbersome to test them in unit test with such protection It might be good to understand why those base methods where overridden instead of the "delegate' one, maybe old artifact on un-refactored components ? |
@@ -369,6 +369,7 @@ class SOFA_CORE_API Base | |||
|
|||
ComponentState getComponentState() const { return d_componentState.getValue() ; } | |||
bool isComponentStateValid() const { return d_componentState.getValue() == ComponentState::Valid; } | |||
bool isComponentStateInvalid() const { return d_componentState.getValue() == ComponentState::Invalid; } |
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.
It seems to be part of an other branch/PR, no ?
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.
no it's not. I use it in the generic methods, before calling the template-specific methods
Yes...
It is exactly what happens now. However, I believe that the tests should not drive the design of a class. Today, I don't have a solution to test the protected methods (even if it's theoretically possible). So I am not against keeping them public. |
Hello, Thanks for the PR. I fully agree on generalizing more the 'delegate' pattern and this is a proper usecase.
In the code base we are making the use of this pattern obvious by using a specific naming scheme (XXXX -> doXXX). BaseData::beginEditVoidPtr()
Data<T>::doBeginEditVoidPtr() I think it would be worth to stick to the scheme for the following reasons:
Of course, this means renaming the the addKToMatrix but in that matter, earlier is better and as the PR is breaking... this may be ok ;) |
The usual pattern of component classes is the following:
DataTypes
(it's not templated). Instead, it acts onVecId
.DataTypes
is known (the class is templated). Therefore, the methods can be defined to work on the right type.IMO, the template-specific method should not be public. In this PR, they are moved to protected. I think also, that the generic methods can be final, but this is breaking, so I am not sure that it is a good idea to keep the final keyword. The PR starts with the
final
keyword to study the consequence on the CI.Those changes force the user to call only the generic methods. I took the opportunity to add a check on the component state in the generic methods. If the final keyword is used, it would ensure that the component state is called before each call of the public API.
By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if