-
Notifications
You must be signed in to change notification settings - Fork 165
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(userspace/libsinsp)!: remove friend
classes, VISIBILITY_PRIVATE
, and VISIBILITY_PROTECTED
#1676
Conversation
…sses Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
…r fields Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Astonishing job, as always @jasondellaluce ! |
/milestone 0.15.0 |
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.
/approve
LGTM label has been added. Git tree hash: 228d9f6305bc9e54a47668933020ab2efd5c1adb
|
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Andreagit97, FedeDP, jasondellaluce The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area libsinsp
/area tests
Does this PR require a change in the driver versions?
What this PR does / why we need it:
In the process of making our APIs clear and stable, I've been hunting for all the single points in which we violate the basic OOP principles of information hiding. We have 2 main ways by which this happens:
friend
classes (thanks C++) and theVISIBILITY_*
macros, by which visibility restrictions of classes can entirely be violated.In this contribution I entirely removed
VISIBILITY_*
and reducedfriend
classes to the bare minimum (only to their legitimate use cases). Although the diff seems big, the changes are very pragmatic. First, I proceeded by putting all the class members and methods that used to be illegally accessed as private, and then I introduced getter and setters wherever applicable so that they could be safely accessed. This all happens in the first commit. Then, the second commit just refactors libsinsp and its tests to use the new accessors instead of doing direct class member access. All the accessors have been inlined so that it makes no difference compared to now at compile-time.It's worth mentioning that I just focused on the things that were illegally accessed, and I didn't add accessors for anything else. The content of this PR, and all the class members/methods involved, is just the minimum set of changes required in order to remove
friends
s andVISIBILITY_*
. If this pattern will be liked, we'll consider adding accessors for other things in the future.Which issue(s) this PR fixes:
Special notes for your reviewer:
This is a potential breaking change for some adopters which relied on the unsafe class member access. The migration path is provided in all cases through the new accessor methods.
Does this PR introduce a user-facing change?: