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.

Love podcasts or audiobooks? Learn on the go with our new app.

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
Martin Cerruti

Martin Cerruti

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

More from Medium

The New Supply Chain - in conversation with Velma Deleveaux

5 Ethical Financing Apps You Should Check Out This 2022

Week in review: 03–09 Jan 2022 — Neurofrontiers

GGs. We all say it, but do we always mean it?