Skip to content
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

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

jasondellaluce
Copy link
Contributor

@jasondellaluce jasondellaluce commented Feb 6, 2024

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 the VISIBILITY_* macros, by which visibility restrictions of classes can entirely be violated.

In this contribution I entirely removed VISIBILITY_* and reduced friend 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 friendss and VISIBILITY_*. 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?:

refactor(userspace/libsinsp)!: remove `friend` classes, `VISIBILITY_PRIVATE`, and `VISIBILITY_PROTECTED`

…sses

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
…r fields

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
@FedeDP
Copy link
Contributor

FedeDP commented Feb 6, 2024

Astonishing job, as always @jasondellaluce !
While there are multiple breaking changes, i think this is a HUGE step forward in the formalization of libs external APIs and a much needed cleanup.
I am all for it, thanks for taking care of doing this!

@FedeDP
Copy link
Contributor

FedeDP commented Feb 6, 2024

/milestone 0.15.0

@poiana poiana added this to the 0.15.0 milestone Feb 6, 2024
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Feb 6, 2024

LGTM label has been added.

Git tree hash: 228d9f6305bc9e54a47668933020ab2efd5c1adb

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Feb 6, 2024

[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:
  • OWNERS [Andreagit97,FedeDP,jasondellaluce]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 73a99e0 into master Feb 6, 2024
34 checks passed
@poiana poiana deleted the refactor/friend-visibility-violations-removal branch February 6, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants