And for virtually anything that is stateful.

I honestly don’t think the problem is with encapsulation as such, but more with poor class design. Should the IV be passed in the encryptor ctor in this example, you’d already have implemented better design in my opinion. Every subsequent call would be using that IV.

Your method would work as well, but it beats the point of having a class instance to begin with — it may as well be a static function.

Software Engineer writing about his daily software adventures, wherever they may lead.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store