Dealing with protected/private methods or properties

By @aaronsaray · 2021-10-21 20:11

Dealing with protected/private methods or properties

  • By @samuel · 2021-10-21 21:35

    Good tip. Generally having to access non-public properties is a sign of poor code, but I see two scenarios when this is useful — when something really shouldn't be public but you just need to test it (without adding accessors either, since the value should really be "hidden"), and when working with third party libraries.

    Third party libraries, especially old ones, often poorly account for people's use cases, so you sometimes have to access or set protected properties even in your normal code. I've had this experience with a few SDKs for some services' APIs.

    Good article!

    • By @aaronsaray · 2021-10-21 21:52

      You're reminding me of some very locked down libraries I've used in the past - with many final classes/methods and private properties - without any dependency injection! :)